Can not delete certain registry settings ?

Oct 6, 2010 at 2:17 PM

I have been trying to figure out how I can have the program delete certain registry's ?
Basically I need to delete  [HKEY_Current_User]comm\ras\book\[SubkeyNameHere]

Everytime i try i get access error with the Rapi2.dll, I have even tried the OpenNetCF.Desktop "This just states the key does not exist" even though i verify it does.

Here is the code i have tried.


using (RemoteDevice.DeviceRegistryKey DeleteRasBookTestKey = DevM.DeviceRegistryCurrentUser.OpenSubKey(@"Comm\RasBook"))




I need to be able to read/write to any part of the device, also this device has be registry unlocked already.


Oct 8, 2010 at 9:36 PM

I hope this is as simple as it appears, but I believe a typo may be causing your problem. You have one key name as "comm\ras\book" and the code has "comm\rasbook" (without the directory separator between "ras" and "book").

Another item of note is that the last two method calls to Close and Dispose are unnecessary since you are using the using clause and DeviceRegistryKey supports IDisposable. You can accomplish the same thing with:

using (RemoteDevice.DeviceRegistryKey DeleteRasBookTestKey = DevM.DeviceRegistryCurrentUser.OpenSubKey(@"Comm\Ras\Book"))
Oct 9, 2010 at 3:04 PM

Sorry this here  [HKEY_Current_User]comm\ras\book\[SubkeyNameHere] < was a typo, it is supposed to be comm\rasbook\SubKeyNameHere.

Still can not delete the registry.

Oct 26, 2010 at 8:56 PM

Make sure the key does not have subkeys. The documentation for IRapiSession.CeRegDeleteKey says the method will fail if there are subkeys.

Nov 30, 2010 at 6:09 AM

it doesnt have subkeys, but lets say it does anyway. How would i delete the subkeys as well... Sorrry for the late response.

Dec 2, 2010 at 6:36 AM

This method should do the trick:

static void DeleteSubKey(RemoteDevice device, RemoteDevice.DeviceRegistryKey key, string subKeyName)
  using (RemoteDevice.DeviceRegistryKey subKey = key.OpenSubKey(subKeyName))
    foreach (var item in subKey.GetSubKeyNames())
      DeleteSubKey(device, subKey, item);
Dec 2, 2010 at 6:17 PM

nice dahall,

That actually made things easier.

I found the reason why i was not able to delete the keys i wanted to delete, the registry was locked, after getting the registry unlocked i now am able to remove the keys and subkeys.


I have one other question though.

Can RAPI2 do a rapiconfig method and load a XML to the phone like rapiconfig.



rapiconfig.exe /p delete-n-set.xml

I ask this because the username and password for internet is encrypted and with rapiconfig, i can tell it the username and password and it will write the correct settings.

Dec 2, 2010 at 8:53 PM

From what I understand, rapiconfig.exe parses an XML file and then uses a number of the RAPI methods to inject settings onto a device. There is not a single rapiconfig method exposed by the library. I re-examined the library to make sure and even tried to decompile the rapiconfig.exe. It uses a number of desktop DLLs and references a number of calls to the original RAPI library (not the COM based on that the project uses).

Dec 2, 2010 at 8:57 PM

Ok so i will just have to build my source with the rapiconfig.exe built into it and just call that to complete the username and password.