Enable/Disable TaskManager

John picture John · May 17, 2013 · Viewed 13.1k times · Source
        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.

Answer

Atiris picture Atiris · May 17, 2013

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