Can only delete registry key once after restarting Windows Mobile handheld

171 Views Asked by At

I'm working on a VB.Net application which is running on Windows Mobile handhelds. I'm using .Net compact framework 3.5. The particular issue I'm experiencing has been replicated on 3 different devices from different manufacturers, one with WM 6.1 and two with WM 5. I am trying to delete a registry key using the code below:

Public Shared Sub DeleteRegistryKey(ByVal RootKey As Microsoft.Win32.RegistryKey, ByVal KeyName As String)
  Try
    Dim RegistryKey As RegistryKey = RootKey.OpenSubKey("Software\COMPANY\Printers\", True)
    RegistryKey.DeleteSubKey(KeyName, True)
    RegistryKey.Flush()
    RegistryKey.Close()
  Catch ex As Exception
    MobileLogging.LogException(ex)
  End Try
End Sub

If I do a soft restart of the device, the code will run perfectly once, and delete the selected key (I have verified this with a registry editor). If I run it again I get an "unauthorizedaccessexception" error. This happens with and without the flush and close calls at the end. I have searched and searched, but have found no solution. Any help would be greatly appreciated.

0

There are 0 best solutions below