Sending the message Ctrl+Alt+Del from my application
Asked Answered
C

7

2

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.

Currant answered 28/2, 2009 at 12:26 Comment(2)
I heard that ctrl alt del combination cannot be called from code. Microsoft implemented that to counter bots. Heard this couple years ago. (btw if you are trying to get the task control window, try ctrl shift esc)Chaechaeronea
I agree. Heard the same thing from a friend when we were learning about 'Hooks'.Azazel
B
5

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.

Barreto answered 28/2, 2009 at 12:51 Comment(1)
Thanks, LockWorkStation() is part of windows.h right? I am not able to compile. Do I need something else ?Currant
R
2

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

Rebuff answered 28/2, 2009 at 12:34 Comment(0)
C
2

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

Cambrel answered 28/2, 2009 at 12:37 Comment(0)
G
1

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.

Georginegeorglana answered 6/10, 2010 at 16:27 Comment(0)
M
0

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.

Mousy answered 28/2, 2009 at 12:36 Comment(0)
C
0

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.

Cock answered 1/3, 2009 at 14:8 Comment(1)
Sure, but only IF the screensaver is configured to be password protected.Roller
O
0

Call the SendSAS function to achieve this.

Oleic answered 9/7, 2016 at 5:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.