Avatar of jlach01

asked on 

Requested registry access is not allowed. - Windows Vista


I'm trying to read/write some registry values in Windows Vista however I keep getting a security permission error. This error only appears when a user has User Account Control on. If they turn UAC off, the error does not show itself. I have tried using RegistryPermissions to Assert() and Demand() permission to no avail. I've also tried requesting permissions through the call to read/write registry in C#. Here's the code I've tried:

            // Demand security permission
            RegistryPermission rm = new RegistryPermission(RegistryPermissionAccess.AllAccess, "HKEY_LOCAL_MACHINE\\SOFTWARE\\Keisense\\PriText");
            // Write the keys
            RegistryKey topKey = Registry.LocalMachine;
            ** RegistryKey ksKey = topKey.OpenSubKey("SOFTWARE\\Keisense\\PriText", RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl);
            if ( ksKey == null ) topKey.CreateSubKey("SOFTWARE\\Keisense\\PriText", RegistryKeyPermissionCheck.ReadWriteSubTree);
            ksKey.SetValue("State", state.ToString());
            string handle = state == 1 ? Handle.ToString() : "";
            ksKey.SetValue("Handle", handle);

The line with the ** at the beginning is where the code is failing. As I said, I've tried rm.Demand() and also rm.Assert(). None of those calls cause the security exception to be thrown.

Any ideas?

Avatar of undefined
Last Comment

8/22/2022 - Mon