-2

I have a Windows application developed with C# and C++ so it has multiple .cs and .cpp files. Now many of the .cs file has the GUID in below format :

[Guid( "D01A42F5-FD89-4c8f-8065-726AD4363411" )]

There are a huge numbers of GUIDs present in my projects. Now I am upgrading the current 32 bit application to 64bit so don't want to have same GUIDs for both the applications.

Is there anyway to replace all the GUIDs without doing it manually? I knew about the options Tools--> Create GUID but for this case I need to replace it manually in all those class files.

Edit: Below two entries are getting conflicted and overrided with later installed application.

Computer\HKEY_CLASSES_ROOT\namespacedll\CLSID

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\namespacedll\CLSID

ksrds
  • 136
  • 2
  • 16
  • I would suggest writing a script in your favorite scripting language to find the Guids and replace them. If you really need to do this. – JonasH Aug 27 '20 at 09:44
  • I don't know any scripting language but C#/.net so could you please help me in this? – ksrds Aug 27 '20 at 09:49
  • @ksrds Then why not write some code in C# to do it? – ProgrammingLlama Aug 27 '20 at 09:51
  • @ksrds then either learn some scripting language (powershell integrates nicely with c#) or write a c# program. In either case some regex might be useful. – JonasH Aug 27 '20 at 09:52
  • Notepad++ could do that for you, [like shown here](https://superuser.com/a/1003801/417194) – nilsK Aug 27 '20 at 09:54
  • @nilsK Visual Studio can do string replacements in files, even with regular expressions. – ProgrammingLlama Aug 27 '20 at 09:57
  • @nilsK : I think Notepad++ will not help in this as we need to create a new GUID and then replace with just one existing GUID. For each GUID we need to create one.Every Class used to have unique ID. – ksrds Aug 27 '20 at 09:58
  • Notepad++ can do everything! https://stackoverflow.com/a/3234633/2590375 ;) @John did not knew that, thank you! – nilsK Aug 27 '20 at 10:01
  • 1
    If you pay close attention you *should* find that every place where the two versions of the program use the same shared registry location, also use the same shared value. Also, don’t rely on source alone to locate conflicts because Windows redirects many of those keys, at runtime, for the 32-bit app only, to shadow locations under a WOW6432Node subkey. Microsoft put a lot of work on Win64 to make sure you wouldn’t have to change GUIDs like you think you need to. I don’t have resources right now for a proper answer but please share exact details of where you think you have a real conflict. – Euro Micelli Aug 31 '20 at 00:04
  • (Microsoft doesn’t just want to make sure you don’t need to update the GUIDs of your COM server to compile a 64-bit version that can live in the same machine, but just as importantly it also wants to make sure *nobody* has to change your COM server’s GUIDs in the source of their COM *clients* that use your server, just because *they* want to make a 64-bit version of their client apps. Microsoft put a lot of work to make sure this was a non-issue for developers) – Euro Micelli Aug 31 '20 at 00:13
  • @EuroMicelli, yes I found the conflict. There is two common entries for both bit applications. HKEY_LOCAL_MACHINE\namespacedll\CLSID and another one is at HKEY_LOCAL_MACHINE\SOFTWARE\Classes\namespacedll\CLSID. It override with the later installed so throws error for first installed as Class not registered. Hope you help me in resolving this issue. – ksrds Aug 31 '20 at 05:29
  • Let’s focus on HKLM\SOFTWARE\Classes. This is just the real location where HKCR lives (HKCR is just an alias). There shouldn’t be anything in that node that is different between the 32-bit and the 64-bit version. Most components only have the CLSID GUID there, and obviously that must be the same for both or you wouldn’t have had to post this question. What do you have there that conflicts? – Euro Micelli Aug 31 '20 at 21:30

2 Answers2

3

Is there anyway to replace all the GUIDs without doing it manually?

Nope.

I also do not understand why this is a problem. 32 and 64 bit generally do not interact, so unless you can make a real point by example or a link to documentation, this looks to me like "busy work" - creating a lot of work with no need.

TomTom
  • 61,059
  • 10
  • 88
  • 148
  • Actually I have a requirement to have both application at the same time. So without changing the GUIDs it;s conflicting the registries so can't have both the application working simultaneously. – ksrds Aug 27 '20 at 09:47
  • 2
    Really? Because to my knowledge 32 and 64 bit registries are separate. The 64 bit application should access the 64 bit registry and not even see the 32 bit values. – TomTom Aug 27 '20 at 10:02
  • Yes, There is two common entries for both bit applications. HKEY_LOCAL_MACHINE\appname.dllname\CLSID and another one is at HKEY_LOCAL_MACHINE\SOFTWARE\Classes\appname.dllname\CLSID It override with the later installed so worked for only second. – ksrds Aug 30 '20 at 16:30
0

My personal approach would be to create an application to read every single project file, regex match/replace each individual GUID with a freshly-generated one.

There is a simpler approach you could take that is unlikely to produce duplicates, and that is to swap and shift parts of the existing GUID values using a regex replace.

So you could match everything with this:

([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])\-([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])\-4([0-9A-F])([0-9A-F])([0-9A-F])\-([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])\-([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])

And then replace it with a shifted/swapped version:

$31$1$30$2$29$3$28$4-$27$5$26$6-4$25$7$24-$8$23$9$22-$10$21$11$20$12$19$13$18$14$17$15$16

Note that this will only work with version 4 GUIDs because we're expecting the static 4 version identifier. Also note that it doesn't actually generate a new GUID; it simply rearranges the existing one. It takes the last character, then the first, then the next last, and then the next last, and so on. The plus side to this is that all GUID values that are currently the same will be the same as each other once the transformation is applied.

Example

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86