The c method for disabling windows's task manager

  • 2020-06-23 01:42:53
  • OfStack

Previous desktop lock screen software has also disabled task manager, but the adoption of a more stupid method, and the operating system has a certain harm. Because task management is in a form that is to say, it is a separate process, so you just need to mandatory to shut down the process that can close the task manager, task management process name for "taskmgr", in a program with a single timer, every 100 milliseconds iterates through all the process of one system open, any process of name the same as the name of the task manager directly closed. Indirectly disabling task management can be achieved, however, this approach should not be used frequently, if the process that frequently forces task management to shut down will disrupt the operating system's message processing. So the desktop management software that was written at that time was not really used.

The principle of disabling task management in this implementation is to directly modify the registry of the system to achieve the purpose of disabling task manager. The registry key of task manager is modified as follows:


HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System

Add one key to this item: DisableTaskmgr. When the value is 1, task manager is disabled. When the value is 0, task manager is enabled.

Having explained the principles above, the code for how to do this with c# is listed below.


        /// <summary>
        ///  Methods to manage the task manager 
        /// </summary>
        /// <param name="arg">0 : Enable task Manager  1 : Disable task Manager </param>
        private void ManageTaskManager(int arg)
        {
            RegistryKey currentUser = Registry.CurrentUser;
            RegistryKey system = currentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System",true );
            // if system Create an item if it does not exist 
            if (system == null)
            {
                system = currentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\System");
            }
            system.SetValue("DisableTaskmgr", arg, RegistryValueKind.DWord);
            currentUser.Close();
        }

By using this method, you can disable the task manager in your program.

Also remember to include the following quote:
Microsoft.Win32;


Related articles: