开发者

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

开发者 https://www.devze.com 2022-12-10 13:54 出处:网络
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 (

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 Ultima开发者_StackOverflow中文版te 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

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\CompanyX


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消