Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to use GetValue to pull a string from a subkey in the reg the below code works fine for HKLU but the same code for HKLM gives permissions errors. I am logged in as admin and the keys exist in the reg.

Works

RegistryKey rkCurrentUser = Registry.CurrentUser;
RegistryKey rkTest = rkCurrentUser.OpenSubKey("Software\\Medcon\\Settings\\Database", true);
string tom = (string)rkTest.GetValue("Database Name");
textBox1.Text = tom;


Does not work
RegistryKey rkLocalMachine = Registry.LocalMachine;
 RegistryKey hostName = rkLocalMachine.OpenSubKey("Software\\Medcon\\Settings\\Database", true);
 string tom = (string)hostName.GetValue("Database Name");
 textBox1.Text = tom;


Apologies I am learning to program from the net and have no formal qualifications.

Cheers Tom
Posted
Comments
skydger 19-Jan-14 14:35pm    
Are you sure you have enough access rights to read LocalMachine registry branch?

1 solution

Just to eliminate one possible cause of an error, try passing false into the OpenSubKey method - this makes the key readonly which is all you need in this case.
 
Share this answer
 

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