Enable/Disable TaskManager

不问归期 提交于 2019-12-19 10:25:45

问题


        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.


回答1:


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



回答2:


Try Deleting the Key instead of setting the value to False




回答3:


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.




回答4:


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:


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" />


来源:https://stackoverflow.com/questions/16610567/enable-disable-taskmanager

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!