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.

ND's
  • 2,155
  • 6
  • 38
  • 59
  • Maybe you need to restart the computer for the changes to take effect? Does the registry key get changed? – jAC May 17 '13 at 13:45
  • yes the regisry key changed when click on disable "0" and click on enable "1"...And i have restart pc but changes doesnt effect.. – ND's May 17 '13 at 13:49
  • 4
    Um, applications should not modify system policies. Only the network administrator should do that, and the way to do it is via the group policy object. – Raymond Chen May 17 '13 at 13:51

5 Answers5

5

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();
    }
Atiris
  • 2,613
  • 2
  • 28
  • 42
1

Try Deleting the Key instead of setting the value to False

David C
  • 3,610
  • 3
  • 21
  • 23
  • Check out this Article : http://www.codeproject.com/Articles/3389/Read-write-and-delete-from-registry-with-C – David C May 17 '13 at 13:52
0

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.

  • While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – JAL Dec 23 '15 at 15:13
0

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

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" />
Jeetendra negi
  • 187
  • 2
  • 9