Link to home
Start Free TrialLog in
Avatar of Masurium
Masurium

asked on

Simulating Ctrl-Alt-Del

I have been trying to simulate a Ctrl+Alt+Del keypress for a Macro program that I am writing.  So far I have tried using the combination of the three using keybd_event, with no success.  I am trying to get through a screen saver (WINNT) which requires me to hit Ctlr-Alt-Del to get to the user/password prompt.

My Macro program has to interact with the GUI (running as a scheduled task), but I want to protect the computer with user passwords and screensaver passwords.  The only way I have been able to figure being able to run this program with the GUI is to also automate the login, and to "break through" the screen saver by automating as well.

I have not been able to find a way to automate a login, but I think I should be able to break through the screen saver.
Avatar of jkr
jkr
Flag of Germany image

Hm, I think this is the wrong approach.

>>I have not been able to find a way to automate a login

Why do you need to automate the login? Have the program run as a service.

>>I should be able to break through the screen saver

Kill the screeensaver using 'TerminateProcess()'.
ASKER CERTIFIED SOLUTION
Avatar of Ichijo
Ichijo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Masurium
Masurium

ASKER

Actually, since I have to both create the security, (and apparently for this macro automation, break through it) I have already modified the default user registry in win95 and win98 machines to force the computer to shutdown if a non-valid user attempts to logon, rather than them be created as a new default user.  So, the security breach is too high.

Thanks for the idea anyways.

you can use the winapi function kbd_event. it works in combination with virtual key codes...

the statement "keybd_event(VK_CONTROL, 0, 0, 0);" whould simulate a press of the ctrl key.
"keybd_event(VK_CONTROL,0, KEYEVENTF_KEYUP, 0);" whould simulate a release of the ctrl key.

the first argument identifies the key.
the second argument is not used.
the third argument denodes a press or a release.
the last argument specifies an additional value associated with the key stroke.

(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/KeyboardInput/KeyboardInputReference/KeyboardInputFunctions/keybd_event.asp)

So for your particular purpose it should be:

keybd_event(VK_CONTROL,0,0,0);         // Control key press
keybd_event(VK_MENU,0,0,0);               // Alt key press
keybd_event(VK_DELETE,0,0,0);            // Delete key press

keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0);         // Control key release
keybd_event(VK_MENU,0,KEYEVENTF_KEYUP,0);               // Alt key release
keybd_event(VK_DELETE,0,KEYEVENTF_KEYUP,0);            // Delete key release

Don't forget to #include <windows.h>

Hope this helps...
  .K.
Thanks, but that was my initial approach.  See the initial question.  I stated: "So far I have tried using the combination of the three using keybd_event, with no success".  Apparently the OS is catching this before it executes for security reasons, basically to prevent exactly what I'm trying to do.