我很难更改注册表中的 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.

我还尝试了以下操作,我看到在执行最后一行时抛出了相同的错误:
RegistrySecurity myRegSecurity = taskMgr.GetAccessControl();
string User = System.Environment.UserName;
myRegSecurity.ResetAccessRule(new RegistryAccessRule(User, RegistryRights.FullControl , AccessControlType.Allow));
taskMgr.SetAccessControl(myRegSecurity); // right here ..

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

最佳答案

您可能有权限问题。

打开regedit,找到您的 key (“政策”)
右键单击该键并选择“权限”

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

关于c# - 编辑 DisableTaskMgr 值时出现 "Cannot write to the registry key"错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11494478/

10-09 18:26
查看更多