|
-
September 1st, 2009, 08:02 AM
#1
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
-
September 1st, 2009, 09:51 AM
#2
Re: Registry - writing to HKLM
Use the LogonUser windows API to impersonate an administrator.
http://msdn.microsoft.com/en-us/libr...oncontext.aspx
-
September 2nd, 2009, 12:49 AM
#3
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.
-
September 2nd, 2009, 09:35 AM
#4
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.
-
September 3rd, 2009, 12:10 AM
#5
Re: Registry - writing to HKLM
is there no possibility to create key directly in HKLM - at any way?
-
September 3rd, 2009, 11:58 PM
#6
Re: Registry - writing to HKLM
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
|