2012-07-15 63 views
4

我在更改注册表中的DisableTaskMgr值时遇到困难。这里就是我试图至今:编辑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 .. 

你有什么解释出了什么问题?在此先感谢:)

+0

我也遇到同样的错误,当我: OpenSubKey(“政策”,真); – vexe 2012-07-15 18:29:07

回答

5

您可能有权限问题。

打开注册表编辑器,找到你的钥匙(“政策”) 右击键,然后选择“权限”

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