Tutorial :Windows 7 - C# Excel Add-In - Registry.GetValue is always returning null


I don't know what's going on here... but the Microsoft.Win32.Registry class is returning all kinds of strange stuff. When I say GetSubKeys it returns a bunch of things that aren't there in regedit (for example, I call Registry.LocalMachine.OpenSubKey("SOFTWARE").SubKeyCount and it returns "81"... but there are only 30 keys when I view it using regedit)

when I try to get the value of something it always returns null.

I have gone through the registry and set permissions on various keys to everyone:full just to test, but still nothing.

am I missing something? I did just upgrade to Windows7 Ultimate from a Vista Ultimate machine...



the actual answer:

Windows 64-bit registry v.s. 32-bit registry

since my laptop is 64bit and my app is 32bit... it was looking under



Since you're opening HKLM, you have to ask for read-only access if you're not running as an Administrator. Just opening the key may or may not work, as Windows can't be sure you're not trying to write to it.

Changing permissions is not the solution, as it just opens a security hole that MS has been trying to close since XP (where it was voluntary to run as non-administrator) and enforcing closure of since Vista's release (where the default is non-administrator).

See this question for a discussion of this subject. It pertains to Delphi, but contains some info and links that you might find useful.

Just out of curiosity, though... Why would an Excel add-in need to read or write to HKLM? Only an installer should be writing to that hive, and file associations are stored in HKCR or HKCU.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »