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;
else
value = 0;
if(RegCreateKeyEx(HKEY_CURRENT_USER,
TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\system"),
0,
NULL,
0,
KEY_SET_VALUE,
NULL,
&hkey,
&dwDisposition)== ERROR_SUCCESS)
{
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
RegSetValueEx(hkey, TEXT("DisableTaskMgr"), 0, dwType, (PBYTE)&value, dwSize);
RegCloseKey(hkey);
}
}
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.
6 comments:
does this even work?
Its working ..... thanks a lot. I was trying the same but for HEKY_LOCAL_MACHINE root. Thank you. :)
Cannot compile in Visual Studio C++ 2008. Illegal blaha blaha. Anyway to walk around?
@someGuy
this was compiled in VC++ 6 - you're better off posting on http://www.stackoverflow.com 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
You are awesome, many thanks for code...people like you become this world much better. XD
@Raúl
thanks for the love, I am just your average .NET butcher ;)
Post a Comment