Registry - writing to HKLM
Hello,
i have problem cause when i try to write to hkey_local_machine, i get an exception with message
Quote:
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
Re: Registry - writing to HKLM
Use the LogonUser windows API to impersonate an administrator.
http://msdn.microsoft.com/en-us/libr...oncontext.aspx
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
Quote:
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
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.
Re: Registry - writing to HKLM
is there no possibility to create key directly in HKLM - at any way?
Re: Registry - writing to HKLM