I'm writing an executable that will either give or take away access to the TaskManager. The problem is some of the computers on my LAN don't have the subkey. I tried to create it but I got this message:
An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
Additional information: Cannot write to the registry key.
Here is my source:
RegistryPermission f = new RegistryPermission(RegistryPermissionAccess.AllAcc ess, "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\ CurrentVersion\\Policies");
//Get the names of the subkeys to determine if the subkey "System" already exists.
RegistryKey temp = Registry.CurrentUser.OpenSubKey("Software\\Microso ft\\Windows\\CurrentVersion\\Policies");
foreach(string subKeyName in temp.GetSubKeyNames())
{
if(subKeyName == "System")
{
RegistryKey nrk = temp.OpenSubKey("System" ,true);
nrk.SetValue("DisableTaskMgr","1");
nrk.Close();
}
else
{
RegistryPermission P = new RegistryPermission(RegistryPermissionAccess.Write, "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\ CurrentVersion\\Policies");
---------------->>> RegistryKey nrk = temp.CreateSubKey("System");
nrk.SetValue("DisableTaskMgr","1");
nrk.Close();
}
As you can see I should theoretically have access because I set the permissions with:
RegistryPermission f = new RegistryPermission(RegistryPermissionAccess.AllAcc ess, "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\ CurrentVersion\\Policies");
Any help would be appreciated.
--------------------------------
From: Sean Riker
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>8UhjH6UAM0aUzD4ONWEMlQ==</Id>