Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I have this code. But it not return result. what i make wrong?

C#
RegistryKey branch = Registry.CurrentUser;
            branch = branch.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall", Microsoft.Win32.RegistryKeyPermissionCheck.ReadSubTree, System.Security.AccessControl.RegistryRights.ReadKey);
            string[] keys = branch.GetValueNames();
Posted
Comments
[no name] 16-Jun-14 18:46pm    
Most likely reason is that there are no values listed under that subkey.

1 solution

it seems GetValueNames return empty collection. check like below, you will get the sub key names and display names.
C#
RegistryKey branch = Registry.CurrentUser;
branch = branch.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall", Microsoft.Win32.RegistryKeyPermissionCheck.ReadSubTree, System.Security.AccessControl.RegistryRights.ReadKey);
var subKeyNames =branch.GetSubKeyNames();
var DisplayNames = new List<string>();
foreach (string subkey_name in branch.GetSubKeyNames())
{
    using (RegistryKey subkey = branch.OpenSubKey(subkey_name))
    {
        DisplayNames.Add((string)subkey.GetValue("DisplayName"));
    }
}


And check below answers as well
C#: How to get installing programs exactly like in control panel programs and features?[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900