Wednesday, March 12, 2008

[C++] How to disable Windows Task Manager

Here's a kick-ass function snippet you can use to lock/unlock Task Manager.
It works setting the appropriate windows registry key. You might wanna do this when you're looking for a way to disable the Ctrl+Alt+Del combination; trapping this particular combination is not as straightforward as trapping the Alt+Tab one or similar, so you can't use the Register/UnregisterHotKey trick (that's gonna be another post).

You'll usually call this function within class contructor/destructor in order to make sure after your object is destroyed you enable back Task Manager (if that's what you want):

void LockTaskManager(bool Lock)
HKEY hkey;
DWORD dwDisposition;
DWORD dwType, dwSize;
DWORD value;

if (Lock)
value = 1;
value = 0;
&dwDisposition)== ERROR_SUCCESS)
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
RegSetValueEx(hkey, TEXT("DisableTaskMgr"), 0, dwType, (PBYTE)&value, dwSize);
RegCreateKeyEx will open the key if existing otherwise it'll create it. The KEY_SET_VALUE parameter on the RegCreateKeyEx is necessary, otherwise you wouldn't be able to set the DisableTaskMgr DWORD value on the reg. This is tested on Win2000 and WinXP SP2.

Enough registry butchering for today.


Anonymous said...

does this even work?

Johnny Idol said...

@Anonymous you bet your ass it does

Prasanna Rani said...

Its working ..... thanks a lot. I was trying the same but for HEKY_LOCAL_MACHINE root. Thank you. :)

some guy said...

Cannot compile in Visual Studio C++ 2008. Illegal blaha blaha. Anyway to walk around?

Johnny Idol said...


this was compiled in VC++ 6 - you're better off posting on with the exact error, chances are it's something fairly trivial! Maybe post alink here in the comments so that I can keep an eye on the thread and update this post

Raúl Infantes said...

You are awesome, many thanks for code...people like you become this world much better. XD

Johnny Idol said...


thanks for the love, I am just your average .NET butcher ;)