Kirill
Kirill

Reputation: 459

GetSubKeyNames by path

I have a path in registry:

HKEY_LOCAL_MACHINE\Software\Windows NT\CurrentVersion\ProfileList

How can I get all folders at ProfileList folder?

I can use method GetSubKeyNames() to string array, but I haven't RegistryKey for ProfileList folder.

Upvotes: 0

Views: 246

Answers (1)

René Vogt
René Vogt

Reputation: 43886

You're key is wrong. To read the profiles you have to use

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList 

So if you want to find the folder for each profile:

using(var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"))
{
    foreach(string name in key.GetSubKeyNames())
    {
        using (var subkey = key.OpenSubKey(name))
            Console.WriteLine(subkey.GetValue("ProfileImagePath"))
    } 
}

Upvotes: 3

Related Questions