In python how to disable Task Manager?

Question:

I tried this code but it didn’t worked:

import subprocess
from time import sleep

si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW

while True:
  subprocess.call("taskkill /F /IM Taskmgr.exe", startupinfo=si)
  sleep(1)

ERROR: The process “Taskmgr.exe” with PID 5220 could not be terminated.

Reason : Access denied.

Asked By: Wyren

||

Answers:

You don’t have sufficient permissions, you should be an Administrator to kill Task Manager.

Execute python.exe as an Administrator. You can do this by right clicking the Python icon and then click “Run as administrator…”.

Answered By: Megabeets

Try this:

import winreg


def disable_task_manager():
    # Path to the explorer properties
    registry_path: str = r"SOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem"
    # Name of the key
    registry_name: str = "DisableTaskMgr"
    # Value that the registry key is set to
    value: int = 1
    try:
        reg_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, registry_path, 0, winreg.KEY_SET_VALUE)
        winreg.SetValueEx(reg_key, registry_name, 0, winreg.REG_SZ, value)
        winreg.CloseKey(reg_key)
    except WindowsError as e:
        print("There was an error setting the registry key {}.format(e))
Answered By: CookieTriste

If you want to make sure that your tkinter window is never closed, you can flood the taskbar, as well as task manager with this script:

import os
from tkinter import *

root = Tk()

while(0==0):
        os.system("python scriptname.py")
Answered By: zonellobster
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.