编辑DisableTaskMgr值时"无法写入注册表项"错误

vex*_*exe 4 c# registry acl

我在更改DisableTaskMgr注册表中的值时遇到了困难.这是我到目前为止所做的尝试:

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.
Run Code Online (Sandbox Code Playgroud)

我也试过以下,看到执行最后一行时抛出同样的错误:

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

你有什么问题的解释吗?提前致谢 :)

Chr*_*ler 5

您可能有权限问题.

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

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