Results 1 to 8 of 8

Thread: [RESOLVED] Help with registry

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Resolved [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");

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help with registry

    What does "it won't work" mean? What actually happens?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    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.

  4. #4
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: Help with registry

    And you do have permissions and you receive no error whatsoever?

  5. #5
    Addicted Member effekt26's Avatar
    Join Date
    Nov 2006
    Posts
    138

    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

  6. #6

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    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.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help with registry

    That's a little convoluted:
    Code:
    RegistryKey key = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\BCMDAlarm");
    
    key.SetValue("Serial", "hisserial");
    key.Close();
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    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
  •  



Click Here to Expand Forum to Full Width