Windows Mobile Registry UnauthorizedAccessException

I wrote three programs that modify the registry in Windows Mobile to install and uninstall the todayscreen plugin for debugging purposes. They worked fine for a while, but one by one they threw "UnauthorizedAccessException" unexpectedly.

See the code for two of the programs below (note that the following code is just directly in Main, so it starts and then the program exits) ...

RegistryInit.exe:

RegistryKey CustomItem = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@"Software\Microsoft\Today\Items\TodayLauncher");
CustomItem.SetValue("Type", 4, RegistryValueKind.DWord);
CustomItem.SetValue("Enabled", 1, RegistryValueKind.DWord);
CustomItem.SetValue("Options", 1, RegistryValueKind.DWord);
CustomItem.SetValue("DLL", @"\Program Files\TodayLauncher\TodayLauncher.dll", RegistryValueKind.String);
CustomItem.SetValue("Config", @"\Program Files\TodayLauncher\Settings.cfg", RegistryValueKind.String);
CustomItem.SetValue("Selectability", 1, RegistryValueKind.DWord);

SendMessage((IntPtr)HWND_BROADCAST, WM_WININICHANGE, 0xF2, 0);

      

RegistryClear:

Microsoft.Win32.Registry.LocalMachine.DeleteSubKey(@"Software\Microsoft\Today\Items\TodayLauncher");
SendMessage((IntPtr)HWND_BROADCAST, WM_WININICHANGE, 0xF2, 0);

      

The third program was a configuration program that had options to add and remove registry keys using exact copies of the above code, but it never worked. For a while he could run the code for "RegistryInit", but it didn't last long. Now, the original RegistryClear program fails, providing the same UnauthorizedAccessException. It is very strange to me that these programs worked for a while and then suddenly stopped working.

Any ideas?

0


a source to share


2 answers


I can see that you are not calling RegistryKey.Close () (like CustomItem.Close () in your example), so the key might still be open and not flushed on disk, which is why you get an UnAuthorizedAccessException?



0


a source


One change I would make is to change "DeleteSubKey" to "DeleteSubKeyTree" as "DeleteSubKey" will fail if there are any subkeys under the key you are deleting.



Have you tried writing them as a native application in C? See if you have the same problems.

0


a source







All Articles