Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetSubKeyNames does not return all keys

Tags:

c#

registry

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?

like image 723
FRules Avatar asked Jan 08 '15 11:01

FRules


2 Answers

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);
like image 58
JimmyV Avatar answered Oct 13 '22 17:10

JimmyV


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

like image 24
bkumarbk Avatar answered Oct 13 '22 19:10

bkumarbk