GetSubKeyNames does not return all keys

安稳与你 提交于 2019-12-21 18:06:17

问题


I want to get the software installed on the client. I use WMI and the registry as well.

I find most of the information under HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL

However, Dropbox for example, does not appear there. Dropbox is located under HKCU so I want to read those keys as well. Simple, I thought, cause the path is the same, just the RegistryHive changes.

Problem

I can not see the key UNINSTALL though when I'm in CurrentVersion using the function GetSubKeyNames.

var root = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32)

var key = root.OpenSubKey(@"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION") // works
var key = root.OpenSubKey(@"SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\Uninstall") // doesnt work

Also I tried this with RegistryView.Registry64 - I get the same result.

Whats printed out when I use GetSubKeyNames is the following:

Device Metadata
Explorer
Group Policy
GrpConv
Internet Settings
Media Center
Run
Shell Extensions
Telephony
ThemeManager
WinTrust

Does anybody know how I can fix this issue?


回答1:


I ran into this issue as well, checking both the 32-bit and 64-bit views worked.

        var HKLM32 = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, "computername", RegistryView.Registry32);
        var HKLM64 = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, "computername", RegistryView.Registry64);
        key32 = HKLM32.OpenSubKey(registryKeytoFind);
        key64 = HKLM64.OpenSubKey(registryKeytoFind);



回答2:


You may use: Registry.LocalMachine.OpenSubKey("Your Key Here").GetSubKeyNames()

But try changing the Platform target to both x86 and x64. You will see two different results.

To change Platform target: Goto Project -> Properties -> Build -> Platform Target Try setting this to X86, print results. Then set to x64, print results



来源:https://stackoverflow.com/questions/27838798/getsubkeynames-does-not-return-all-keys

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!