views:

494

answers:

7

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.

Thanks.

I want to Send Ctl+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.

+2  A: 

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 :)

Paul Dixon
A: 

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.

Robert Gould
+2  A: 

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

overstood
+5  A: 

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 [email protected] 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.

Serge - appTranslator
Thanks, LockWorkStation() is part of windows.h right? I am not able to compile. Do I need something else ?
aJ
no. winuser.h. lib = user32.lib
Serge - appTranslator
A: 

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.

Tommy
A: 

It's a very classic Win32 question. No need of SASlib of course !

See on Win32 Group for the well-known official method.

+1  A: 

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.

Remko