Access denied when modifying Registry Key

Dec 8, 2011 at 2:38 PM


I checked all the discussions but I couldn't find any information about the error I am getting.

Basically, I want to modify the key (on my device) in Security\Policies\Polices called "0000101a" to 1.

I'm executing the following code:

using (RemoteDevice.DeviceRegistryKey hKey = device.DeviceRegistryLocalMachine.OpenSubKey(@"Security\Policies\Policies"))
    hKey.SetValue("0000101a", 1, Microsoft.Win32.RegistryValueKind.DWord);

I am getting the exception:

System.Devices.RapiException : Access is denied
System.Devices.RemoteDevice.DeviceRegistryKey.SetValue(String name, Object value, RegistryValueKind valueKind)

Is this a limitation in RAPI2? Thanks in advance.

Dec 8, 2011 at 7:56 PM

The OpenSubKey method opens a registry key as read-only as stated in the documentation for that method. You must use CreateSubKey in order to use SetValue.

Dec 9, 2011 at 10:00 AM


Thanks a lot for your speedy response. I changed this to:

using (var key = device.DeviceRegistryLocalMachine.CreateSubKey(@"Security\Policies\Policies"))
    key.SetValue("0000101a", 1, Microsoft.Win32.RegistryValueKind.DWord);

Still get the same error: Access Denied

To be honest, I'm now thinking this could be because of actual security restrictions.

It wouldnt suprise me if you couldnt edit these registry values remotely.


Dec 12, 2011 at 11:13 PM

If you are getting the error on the CreateSubKey line, then I would have to agree with you. You could always install a registry editor on the device and confirm your supposition.