简体   繁体   中英

Registry CreateSubKey not working and no receiving error

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.

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.

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.

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