0

I'm writing a winforms app in C# and for part of it I want to store data in the registry. The data are licence keys and the app I've written is running with elevated (Administrator) permissions. The location where I want to store the values is: HKEY_LOCAL_MACHINE\SOFTWARE\MyCompanyName\MyAppName\Licences. I want it stored in LOCAL_MACHINE and not CURRENT_USER because I'm licencing the machine, not the user.

When inspecting the registry I am using %systemroot%\syswow64\regedit and running with Administrator permissions. I've additionally checked with c:\Windows\regedit too. For both the following is true. I'm running 64 bit Windows 8.1 Pro (don't laugh).

The code runs without error and stores the data. It also reads it back correctly too. However, the value is not created at the key location. Instead, having searched the registry for the value I created, it is being created at four places:

HKEY_CLASSES_ROOT\VirtualStore\MACHINE\SOFTWARE\Wow6432Node\MyCompanyName\MyAppName\Licences

HKEY_CURRENT_USER\Software\Classes\VirtualStore\MACHINE\SOFTWARE\Wow6432Node\MyCompanyName\MyAppName\Licences

HKEY_USERS\S-1-5-21-1518458450-3113483475-3039049429-1106\Software\Classes\VirtualStore\MACHINE\SOFTWARE\Wow6432Node\MyCompanyName\MyAppName\Licences

HKEY_USERS\S-1-5-21-1518458450-3113483475-3039049429-1106_Classes\VirtualStore\MACHINE\SOFTWARE\Wow6432Node\MyCompanyName\MyAppName\Licences

So, a few questions. Am I using the right version of regedit? If so, how do I get my licences to write to the location I require? Why are they turning up in these other places?

Thank you for any assistance rendered.

Mark Roworth
  • 409
  • 2
  • 15
  • You have a 32bit app and maybe you're impersonating an User that is not the current logged in User. – Jimi Sep 24 '21 at 12:28
  • This may be helpful: https://stackoverflow.com/questions/869783/windows-64-bit-registry-v-s-32-bit-registry – edtheprogrammerguy Sep 24 '21 at 12:29
  • Those locations are exactly where [Registry Virtualization](https://learn.microsoft.com/en-us/windows/win32/sysinfo/registry-virtualization) will write to. – Damien_The_Unbeliever Sep 24 '21 at 12:30
  • Also, your "four places" are 1 place. `HKEY_CLASSES_ROOT` is a virtual key which merges keys from `HKEY_LOCAL_MACHINE\Software\Classes` and `HKEY_CURRENT_USER\Software\Classes`. And `HKEY_CURRENT_USER` always shows you the contents of one of the keys under `HKEY_USERS`, whichever one matches the SID of the logged in user. – Damien_The_Unbeliever Sep 24 '21 at 13:15
  • Ah, thank you. I've recompiled in 64-bit mode and get a registry entry in the right place. Thank you all for the explanation. – Mark Roworth Sep 24 '21 at 13:49

0 Answers0