Enable/Disable TaskManager

2019-02-20 02:27发布

        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.

标签: c# .net regedit
5条回答
beautiful°
2楼-- · 2019-02-20 02:53

for disabling TaskManager you must set a DWord string in Registry( User Local Machine instead of Current User). Use following code.( It not working in 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();

for That user application must run under Admin Permission. change following change in app.manifest for using application in Admin Permission

 <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
查看更多
手持菜刀,她持情操
3楼-- · 2019-02-20 03:01

Yes, delete will work. Means, use this code to toggle:

    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();
    }

or this code to set:

    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();
    }
查看更多
Deceive 欺骗
4楼-- · 2019-02-20 03:04

answer 4 is Okey But Uu need one more litte code this %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(); 
查看更多
在下西门庆
5楼-- · 2019-02-20 03:08

Try this:

 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();
    }

For Enable/Desable: (Sorry, my English is very bad...)

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

Note: You must have administrator access to run the program.

查看更多
在下西门庆
6楼-- · 2019-02-20 03:13

Try Deleting the Key instead of setting the value to False

查看更多
登录 后发表回答