简体   繁体   中英

RegistryKey.OpenSubKey() Not working properly

I want to get postrgeSQL installation and data directory path from the registry with the following code:

RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\PostgreSQL\Installations");
foreach (var k in key.GetSubKeyNames())
{

}

However, that does not work for me, as

key.GetSubKeyNames()

says it is null. How can I solve that?

Check your user access to the registry key. If you don't have access your code will return null. You can do this by running regedit, right clicking on the registry key and selecting "permissions".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM