|
-
Jul 12th, 2007, 02:18 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Help with registry
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.
Code:
RegistryKey RegInfo = Registry.LocalMachine;
RegInfo.CreateSubKey("BCMDAlarm");
RegInfo.SetValue("StringName", "value");
-
Jul 12th, 2007, 02:47 AM
#2
Re: Help with registry
What does "it won't work" mean? What actually happens?
-
Jul 12th, 2007, 04:33 AM
#3
Thread Starter
Fanatic Member
Re: Help with registry
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.
-
Jul 12th, 2007, 10:27 AM
#4
Re: Help with registry
And you do have permissions and you receive no error whatsoever?
-
Jul 12th, 2007, 11:30 PM
#5
Addicted Member
Re: Help with registry
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
-
Jul 13th, 2007, 02:03 AM
#6
Thread Starter
Fanatic Member
Re: Help with registry
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.
Code:
string KeyName = @"SOFTWARE\BCMDAlarm";
RegistryKey RegInfo = Registry.LocalMachine;
RegInfo.CreateSubKey(KeyName);
RegInfo.Close();
Registry.SetValue(@"HKEY_LOCAL_MACHINE\" + KeyName, "Serial", "hisserial");
Last edited by daimous; Jul 13th, 2007 at 02:34 AM.
-
Jul 13th, 2007, 02:57 AM
#7
Re: Help with registry
That's a little convoluted:
Code:
RegistryKey key = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\BCMDAlarm");
key.SetValue("Serial", "hisserial");
key.Close();
-
Jul 13th, 2007, 03:10 AM
#8
Thread Starter
Fanatic Member
Re: Help with registry
Oh..Thanks for making it simple Jm.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|