4

I'm having difficulty changing the DisableTaskMgr value in the registry. Here's what I'm trying so far:

RegistryKey taskMgr = Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Policies");

string[] subKeys = taskMgr.GetSubKeyNames();
bool foundSystemKey = false;
foreach (string s in subKeys)
  if (s == "System")
  {
    foundSystemKey = true;
    break;
  }
if (!foundSystemKey)
{
  taskMgr = taskMgr.CreateSubKey("System"); 
// here is where I'm getting the exception even when I do OpenSubkey("Policies" , true)
}

taskMgr.OpenSubKey("System", true);
taskMgr.SetValue("DisableTaskMgr", 1); // 0 to enable, 1 to disable.

I've also tried the following, am seeing the same error get thrown while executing the last line:

RegistrySecurity myRegSecurity = taskMgr.GetAccessControl();
string User = System.Environment.UserName;
myRegSecurity.ResetAccessRule(new RegistryAccessRule(User, RegistryRights.FullControl , AccessControlType.Allow));
taskMgr.SetAccessControl(myRegSecurity); // right here ..

Do you have any explanation as to what's going wrong? Thanks in advance :)

4

1 回答 1

5

您可能有权限问题。

打开注册表,找到您的密钥(“策略”)右键单击该密钥并选择“权限”

我可以继承权限,但请尝试添加“所有人”并重新运行您的代码。如果可行,请删除“Everyone”并决定一个新的组名,将新组添加到域或本地计算机。然后将新组添加到密钥,然后将需要权限的所有用户添加到新组。

于 2012-07-15T18:32:20.297 回答