August 27th, 2018

How do I force the Task Manager window closed whenever it opens?

A customer wanted to close (or at least hide) the Task Manager window whenever it opens. They did so by setting a timer and periodically running this code:

void FindAndCloseTaskManager()
{
  HWND taskManagerWindow = FindWindow(nullptr, "Windows Task Manager");
  if (taskManagerWindow) {
    PostMessage(taskManagerWindow, WM_CLOSE, 0, 0);
  }
}

This code worked on Windows 7, but stopped working on Windows 8.

Well, yeah, because you’re searching for a window by name. The name of the Task Manager window in Windows 7 was Windows Task Manager:

On the other hand, in Windows 8, the window was named simply Task Manager.

And of course, those names apply only to English. If the user’s UI language is German, the name will be Task-Manager with a hyphen.

Whether a user can or cannot run Task Manager is an administrative decision, not an application decision. Use the “Remove Task Manager” group policy.

Bonus chatter: Note that if this customer had their way, the name of Task Manager would be a compatibility constraint.

Bonus bonus chatter: Don’t think you can rely on the window class name either. That is also subject to change.

Topics
Other

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.