Trying to do the simple task of writing to the registry to make a C# application run at startup.
Using the basic Win32.RegistryKey
setup but for some reason it keeps adding my keys into the /SOFTWARE/WOW6432/Microsoft/Windows..
etc directory instead of plain ol /SOFTWARE/Microsoft/Windows..
Tried reading up on it a bit but there didn't seem to be a simple answer to this question:
How to I specifically write a key to the /SOFTWARE/Microsoft/Windows
Registry Key instead of it writing to WOW6432
? I've checked to make sure my Visual C# Express solution file had the platform listed as x86... so it's compiling correctly... I just don't want that wow6432
directory.
Thanks for any advice!
Edit:
I'm now using the following and still no success:
Microsoft.Win32.RegistryKey localKey32 = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry64);
Your process targets x86 (i.e. it is a 32-bit process) and when run on a 64-bit machine under the WOW64 emulator, registry redirection comes into play. For certain parts of the registry the system maintains two distinct views, one for 32 bit processes and one for 64 bit processes. The list of keys affected by redirection is here: Registry Keys Affected by WOW64.
Redirection is transparent to an application. A 32 bit process access HKLM\Software
and does not know (indeed does not need to know), that the 64 bit OS is actually accessing HKLM\Software\Wow6432Node
.
You have a number of options available to you:
RegistryView
enumeration. However, note that this functionality requires .net 4 and for earlier versions of .net, p/invoke is required to open views of the registry.HKLM\Software
. A 64-bit system will read both views of the registry when processing the run at startup registry keys. In other words your existing approach already works!As a final point I would comment that the task of setting up this registry key is best left to an installation program. Modify keys under HKLM\Software
requires admin rights and typically you can only expect to have admin rights at install time.
Try to explicitly open the registry in 64 bit
view by using Registry64
in RegistryView. Similarly you can open 32 bit
view using Registry32
option
According to MSDN
You can specify a registry view when you use the OpenBaseKey and OpenRemoteBaseKey(RegistryHive, String, RegistryView) methods, and the FromHandle property on a RegistryKey object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With