Click to See Complete Forum and Search --> : [RESOLVED] Help with registry
daimous
Jul 12th, 2007, 02:18 AM
hi guys! im trying to add a subkey, "mySubKey", in LocalMachine but it wont work but when i try to add it in CurrentUser it works...any idea guys what the problem is? by the way, im login as administrator.
RegistryKey RegInfo = Registry.LocalMachine;
RegInfo.CreateSubKey("BCMDAlarm");
RegInfo.SetValue("StringName", "value");
jmcilhinney
Jul 12th, 2007, 02:47 AM
What does "it won't work" mean? What actually happens?
daimous
Jul 12th, 2007, 04:33 AM
Sorry for that. What i mean is, the subkey does not appear in LocalMachine(HKEY_LOCAL_MACHINE) after I executed the code above. But when I use .CurrentUser in lieu of .LocalMachine the subkey appears in HKEY_CURRENT_USER.
nmadd
Jul 12th, 2007, 10:27 AM
And you do have permissions and you receive no error whatsoever?
effekt26
Jul 12th, 2007, 11:30 PM
wouldnt you want your "BCMDAlarm" to actually be in the SOFTWARE folder...as in...
"HKLM\SOFTWARE\BCMDAlarm"
what you are trying to do is is create the following...
"HKLM\BCMDAlarm"
I didnt think you could write to the root HKLM key...(correct me if im wrong please...)?
Cheers, Justin
daimous
Jul 13th, 2007, 02:03 AM
Oh! my fault. My code above is logically wrong..Because what I want is first, create a subkey "BCMDAlarm" in LocalMachine. Second, add Value "StringName" under subkey "BCMDAlarm" that I have just created. But what the code above will do is to create the value "StringName" under LocalMachine and not under "BCMDAlarm" subkey. I have the code here below is the right one.
string KeyName = @"SOFTWARE\BCMDAlarm";
RegistryKey RegInfo = Registry.LocalMachine;
RegInfo.CreateSubKey(KeyName);
RegInfo.Close();
Registry.SetValue(@"HKEY_LOCAL_MACHINE\" + KeyName, "Serial", "hisserial");
jmcilhinney
Jul 13th, 2007, 02:57 AM
That's a little convoluted:RegistryKey key = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\BCMDAlarm");
key.SetValue("Serial", "hisserial");
key.Close();
daimous
Jul 13th, 2007, 03:10 AM
Oh..Thanks for making it simple Jm.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.