I’m writing this program that will need to access the registry to pull some info on the machine. It should always be run by someone in the Local Admin group, and it will be used on Server 2003 and 2008 machines. Basically it’s been working fine for the most part on the box that I’m mainly writing it on, as well as my test 2003 and 2008 servers. The problem is, when I get on my laptop, which is running Windows 7, I cannot seem to use it for testing as I’m getting errors when trying to read or write the registry below HKEY_LOCAL_MACHINE\SOFTWARE.
I’m logged in as a user who is a local admin, and I can run Regedit to create a key, such as test9999. If I use the following it will always come back null.
RegistryKey testKey = Registry.LocalMachine.OpenSubKey(“SOFTWARE\test9999”);
I’ve tried dropping the subkey and SOFTWARE will return, but I haven’t been able to get anything below that.
I’m using MS VC# Express and I’ve tried running it “as Administrator” as well as trying to run the .exe’s the same way, but it still continues to return null for anything below Software. What am I missing?
Turns out registry redirection behavior for 32 bit processes running on 64 bit Windows was changed in Windows 7 and Windows 2008 R2, which may explain why it works on Windows 2008 (not R2 I assume) and not on Windows 7.
Read more about it here: http://msdn.microsoft.com/en-us/library/aa384232(v=vs.85).aspx