3
        public static void ToggleTaskManager(string keyValue)
        {
            RegistryKey objRegistryKey = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System");
            objRegistryKey.SetValue("DisableTaskMgr", keyValue);
            objRegistryKey.Close();
        }


        private void btnDisableTaskManager_Click(object sender, EventArgs e)
        {
            ConsoleDisplay.ToggleTaskManager("1");
        }

        private void btnEnableTaskManager_Click(object sender, EventArgs e)
        {
            ConsoleDisplay.ToggleTaskManager("0");
        }

For Disable/Enable TaskManager used above function but when i disable first time then it disable correctly.But when i click on enable button TaskManager not enabled.

4

5 回答 5

5

是的,删除将起作用。意味着,使用此代码切换:

    public void ToggleTaskManager()
    {
        RegistryKey objRegistryKey = Registry.CurrentUser.CreateSubKey(
            @"Software\Microsoft\Windows\CurrentVersion\Policies\System");
        if (objRegistryKey.GetValue("DisableTaskMgr") == null)
            objRegistryKey.SetValue("DisableTaskMgr", "1");
        else
            objRegistryKey.DeleteValue("DisableTaskMgr");
        objRegistryKey.Close();
    }

或此代码设置:

    public void SetTaskManager(bool enable)
    {
        RegistryKey objRegistryKey = Registry.CurrentUser.CreateSubKey(
            @"Software\Microsoft\Windows\CurrentVersion\Policies\System");
        if (enable && objRegistryKey.GetValue("DisableTaskMgr") != null)
            objRegistryKey.DeleteValue("DisableTaskMgr");
        else
            objRegistryKey.SetValue("DisableTaskMgr", "1");
        objRegistryKey.Close();
    }
于 2013-05-17T14:09:17.713 回答
1

尝试删除键而不是将值设置为 False

于 2013-05-17T13:48:47.557 回答
0

尝试这个:

 public void SetTaskManager(bool enable)
    {
        RegistryKey objRegistryKey = Registry.CurrentUser.CreateSubKey(
            @"Software\Microsoft\Windows\CurrentVersion\Policies\System");
        if (enable && objRegistryKey.GetValue("DisableTaskMgr") != null)
            objRegistryKey.DeleteValue("DisableTaskMgr");
        else
            objRegistryKey.SetValue("DisableTaskMgr", "1");
        objRegistryKey.Close();
    }

对于启用/禁用:(对不起,我的英语很糟糕......)

 private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        switch (e.KeyCode)
        {
            case Keys.F1:
                {
                    SetTaskManager(Convert.ToBoolean(1));
                }
                break;
        }

注意:您必须具有管理员访问权限才能运行该程序。

于 2015-12-23T14:50:48.460 回答
0

答案 4 是好的,但是你需要一个小代码这个 %100 true ( RegistryValueKind.DWord );

RegistryKey objRegistryKey = Registry.CurrentUser.CreateSubKey(
        @"Software\Microsoft\Windows\CurrentVersion\Policies\System");
        if (objRegistryKey.GetValue("DisableTaskMgr") == null)
            objRegistryKey.SetValue("DisableTaskMgr", "1", RegistryValueKind.DWord);
        else
            objRegistryKey.DeleteValue("DisableTaskMgr");
        objRegistryKey.Close(); 
于 2016-05-09T01:27:42.597 回答
0

要禁用 TaskManager,您必须在注册表中设置一个 DWord 字符串(用户本地计算机而不是当前用户)。使用以下代码。(它在 Windows 7 中不起作用)

Microsoft.Win32.RegistryKey key;
key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",true);
key.SetValue("DisableTaskMgr", "1", RegistryValueKind.DWord);
key.Close();

对于该用户应用程序必须在管理员权限下运行。更改 app.manifest 以在管理员权限中使用应用程序

 <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
于 2018-10-13T04:36:19.650 回答