I want to write a small utility in MFC
which sends the Ctrl+Alt+Del message to OS. Can any one help me how do I achieve this? I tried:
::PostMessage(HWND_BROADCAST, WM_HOTKEY, 0, MAKELONG( MOD_CONTROL | MOD_ALT, VK_DELETE));
But this is not working.
I want to send Ctrl+Alt+Del not to invoke TaskMgr.exe
. Also, it is for my local OS (Windows XP Service pack 2). Basically I want to use this application to lock my machine and schedule some actions along with locking.
This is not a keystroke you can simulate. It's called the "Secure Attention Sequence".
Here's how to invoke it FROM A REMOTE DESKTOP (XP+ solution):
include <shldisp.h>
IShellDispatch4 *pShell;
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER,
IID_IShellDispatch, (void**)&pShell);
if(SUCCEEDED(hr))
pShell->WindowsSecurity();
CoUninitialize();
The only solution to invoke it from the local desktop is to use SASLib. It's not public. Write a note to saslib@microsoft.com to request it.
EDIT: Wait! You want to lock the machine? Just call LockWorkStation()! Click the link for more info about header file, lib file et all other details.
Since VNC can let you do this to a remote system, it must be possible. If I were you, I'd trawl through the source to UltraVNC. Then I'd post the answer the here :)
Do you need to send control+alt+delete or do you just want to bring up the task manager?
If you just need to bring up the task manager you can simply run \Windows\System32\taskmgr.exe
I know it's an old questions but I am posting my solutions here in case someone looking for a solution arrives here. The part1 and part2 articles explain how Winlogon registers the CAD sequence and provides code examples on how to use it.
- Send CAD and Unlock workstation for Windows XP - Part 1 (free)
- Send CAD and Unlock workstation for Windows XP - Part 2 (free)
- SasLibEx for Vista and higher (sorry, this is not free)
Wouldn't it be easier to just ask the machine to shut down or logout? That key combination isn't really a good idea? You can send these messages.
Can't you start a screensaver and it will take care of the locking for you? I don't have a Windows machine available right now, but I recall one could lock the workstation like this.
Call the SendSAS
function to achieve this.