CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2007
    Posts
    32

    Registry - writing to HKLM

    Hello,
    i have problem cause when i try to write to hkey_local_machine, i get an exception with message
    The parameter is incorrect.
    the code looks like this:
    Code:
    objReg = Registry.LocalMachine;
    RegistryKey obj = objReg.OpenSubKey(Key, true);
                    
                    if (obj == null) 
                    {
                        objReg.CreateSubKey(Key).SetValue(Value, "");
                    }
                    else
                    {
                        objReg.SetValue(Value, "");
                    }
    i was looking for the solution in the internet, but i only found that the couse can be the lack of administrator privileges..
    i added this part:
    Code:
        [assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum, ViewAndModify = "HKEY_LOCAL_MACHINE")]
    With no result
    do you know what cases this problem?
    Cheers

  2. #2
    Join Date
    Jul 2006
    Posts
    297

    Re: Registry - writing to HKLM

    Use the LogonUser windows API to impersonate an administrator.

    http://msdn.microsoft.com/en-us/libr...oncontext.aspx

  3. #3
    Join Date
    Feb 2007
    Posts
    32

    Re: Registry - writing to HKLM

    but there is one more problem..
    my username is in administrators group but in spite of this when i open regedit and click add->key in HKEY_LOCAL_MACHINE, i get the message
    Cannot create key: Error writing to the registry
    so i think even if i impersonate an administrator it won't work, cause it doesn't work even through regedit...

    edit
    maybe i should add that i want to craete key directly in HKLM
    e.g. HKLM\myKey

    and i can create keys like: HKLM\Hardware\myKey
    Last edited by Ka-lolek; September 2nd, 2009 at 01:06 AM.

  4. #4
    Join Date
    Jul 2006
    Posts
    297

    Re: Registry - writing to HKLM

    You can't Make a new key in that directory. Must choose one of the subdirectorys HARDWARE, SAM, SECURITY, SOFTWARE, or SYSTEM.

  5. #5
    Join Date
    Feb 2007
    Posts
    32

    Re: Registry - writing to HKLM

    is there no possibility to create key directly in HKLM - at any way?

  6. #6
    Join Date
    Feb 2007
    Posts
    32

    Re: Registry - writing to HKLM

    bump

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

Featured