Reputation: 3
i did this before and that was a simple code. here is my code
private void button1_Click(object sender, EventArgs e)
{
var k1 = Registry.LocalMachine.OpenSubKey("SOFTWARE", true).CreateSubKey("test");
}
im looking regedit HKEY_LOCAL_MACHINE-SOFTWARE and WOW6432Node. i cant find test key in there.
my user is an administrator.
i didnt receive an error.
maybe it has easy solution but im working for 45 minutes and i cant solve this problem. thank you for helping.
Upvotes: 0
Views: 1558
Reputation: 3
i tried SetValue like your code and i receive securityexception.
i build my program then i started my exe as administrator and no error. also i could GetValue. however i cant see in regedit yet. when i searhing "test" (ctrl+f) on regedit i cant find either.
is that a problem i dont know. it work now just troublesome :)
Update: i quit regedit then i start over and over but when i refresh i could see test -_- such an idiot.
Upvotes: 0
Reputation: 17868
Are you sure you're looking for the right thing? Registry can be a fickle thing..
I ran
RegistryKey k1 = Registry.LocalMachine.OpenSubKey("SOFTWARE", true).CreateSubKey("test");
k1.SetValue("my value","here");
Nothing shows yet in regedit - somethings dont quickly show because it depends when it was read.
however ending app, and running
RegistryKey k1 = Registry.LocalMachine.OpenSubKey("SOFTWARE", true).CreateSubKey("test");
Console.WriteLine(k1.GetValue("my value"));
Shows my value is there.
Upvotes: 1