1

This line works:

RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(
    baseKeyName + subKey, RegistryKeyPermissionCheck.ReadWriteSubTree);

While these lines produce a SecurityException - Requested registry access is not allowed on the OpenSubKey line:

RegistryKey baseKey = RegistryKey.OpenBaseKey(
   RegistryHive.LocalMachine, RegistryView.Registry32);
RegistryKey registryKey = baseKey.OpenSubKey(
   baseKeyName + subKey, RegistryKeyPermissionCheck.ReadWriteSubTree);

On the same Win7 machine.

I'm doing it this way because in the 'real' code there is a conditional that will use the the Registry64 RegistryView on 64 bit machines.

Anyone got any ideas or workarounds?

Brian
  • 5,069
  • 7
  • 37
  • 47

1 Answers1

0

Writing to the LocalMachine registry area is not allowed unless the application is running elevated as an administrator.

Daniel
  • 8,794
  • 4
  • 48
  • 71
  • It was running at administrator level. – user2284443 Apr 25 '13 at 06:09
  • After further testing it appears that you can only use the RegistryView approach on a 64 bit machine ie where there is both 32 and 64 bit registry views. If you use it in a 32 bit Win7 as I was you get a security exception. – user2284443 Apr 25 '13 at 06:12