I have some C# code I am using to delete a subkey and its tree from the
registry however I am running into some issues.
At first, I was using the Registry.LocalM achine.DeleteSu bKeyTree method and
passing it a string like this:
SubKeyBase = @"SYSTEM\Curren tControlSet\Enu m\";
Registry.LocalM achine.DeleteSu bKeyTree(SubKey Base + InstanceID);
The variable InstanceID had something like this in it:
USB\VID_xxxx&PI D_xxxx\xxxxxxxx xxxxx
This is the instance ID of a USB device and it correlates exactly to the
information stored about the device in the registry. By appending these two,
I came up with the path to the registry key/tree that I wanted to delete:
HKEY_LOCAL_MACH INE\SYSTEM\Curr entControlSet\E num\USB\VID_xxx x&PID_xxxx\xxxx xxxxxxxxx
Using this approach, I was getting an ArgumentExcepti on saying that the key
does not exist, however I could open up regedit and the key was there and I
could delete it manually if I wanted without a problem. So since I couldn't
figure out what was going on, I decided to use OpenSubKey to open the path
defined by SubKeyBase (ie. "SYSTEM\Current ControlSet\Enum ") and then use that
RegistryKey object to delete the key/tree I needed and see if I got any
different result.
RegistryKey rk = Registry.LocalM achine.OpenSubK ey(SubKeyBase, true);
(The 2nd argument with a value of true is to indicate I need write access)
Well, this statement is throwing a SecurityExcepti on even though I can
manually open up regedit and delete the key. I am a fairly new to the .NET
framework so I am not sure what I need to give my application the security
clearance to perform these operations. I was under the impression that it
automatically inherited the security profile of the user running the
application but it seems this is not the case.
Any help is greatly appreciated!
Regards,
David K
registry however I am running into some issues.
At first, I was using the Registry.LocalM achine.DeleteSu bKeyTree method and
passing it a string like this:
SubKeyBase = @"SYSTEM\Curren tControlSet\Enu m\";
Registry.LocalM achine.DeleteSu bKeyTree(SubKey Base + InstanceID);
The variable InstanceID had something like this in it:
USB\VID_xxxx&PI D_xxxx\xxxxxxxx xxxxx
This is the instance ID of a USB device and it correlates exactly to the
information stored about the device in the registry. By appending these two,
I came up with the path to the registry key/tree that I wanted to delete:
HKEY_LOCAL_MACH INE\SYSTEM\Curr entControlSet\E num\USB\VID_xxx x&PID_xxxx\xxxx xxxxxxxxx
Using this approach, I was getting an ArgumentExcepti on saying that the key
does not exist, however I could open up regedit and the key was there and I
could delete it manually if I wanted without a problem. So since I couldn't
figure out what was going on, I decided to use OpenSubKey to open the path
defined by SubKeyBase (ie. "SYSTEM\Current ControlSet\Enum ") and then use that
RegistryKey object to delete the key/tree I needed and see if I got any
different result.
RegistryKey rk = Registry.LocalM achine.OpenSubK ey(SubKeyBase, true);
(The 2nd argument with a value of true is to indicate I need write access)
Well, this statement is throwing a SecurityExcepti on even though I can
manually open up regedit and delete the key. I am a fairly new to the .NET
framework so I am not sure what I need to give my application the security
clearance to perform these operations. I was under the impression that it
automatically inherited the security profile of the user running the
application but it seems this is not the case.
Any help is greatly appreciated!
Regards,
David K
Comment