Simulate ctrl + alt + delete

Source: Internet
Author: User

When we write remote control software, we will find that to unlock the server, we have to send virtual keys of these three keys.

Next, let's talk about the solution process.


1. At the beginning, we decided to use keybd_event () to simulate the keyboard.

Keybd_event (VK_CONTROL, MapVirtualKey (VK_CONTROL, 0), 0, 0 );
Keybd_event (VK_MENU, MapVirtualKey (VK_MENU, 0), 0, 0 );
Keybd_event (VK_DELETE, MapVirtualKey (VK_DELETE, 0), 0, 0 );
Keybd_event (VK_DELETE, MapVirtualKey (VK_DELETE, 0), KEYEVENTF_KEYUP, 0 );
Keybd_event (VK_MENU, MapVirtualKey (VK_MENU, 0), KEYEVENTF_KEYUP, 0 );
Keybd_event (VK_CONTROL, MapVirtualKey (VK_CONTROL, 0), KEYEVENTF_KEYUP, 0 );
It is found that only the effects of ctrl + alt can be simulated, but the other two keys can be simulated, such as win + d. I don't know if keybd_event () can only simulate two keys or because
Ctrl + alt + delete special, I hope you can tell me, thank you.

2. use PostMessage (HWND_BROADCAST, WM_HOTKEY, 0, MAKELONG (MOD_ALT | MOD_CONTROL, VK_DELETE); to send a virtual keyboard, but there are still many things to do in the winNT system, for example: openDesktop (), OpenInputDesktop (), GetThreadDesktop (), SetThreadDesktop (), CloseDesktop (), GetUserObjectInformation ()

The Code is as follows:


# Include "windows. h"
BOOL simulateAltControlDel ();
Void main ()
{
SimulateAltControlDel ();
}
BOOL simulateAltControlDel ()
{
HDESK hsf-current;
HDESK hdesk;
HWINSTA hwinstaCurrent;
HWINSTA hwinsta;
//
// Save the current Window station
//
HwinstaCurrent = GetProcessWindowStation ();
If (hwinstaCurrent = NULL)
Return FALSE;
//
// Save the current desktop
//
Hsf-current = GetThreadDesktop (GetCurrentThreadId ());
If (hsf-current = NULL)
Return FALSE;
//
// Obtain a handle to WinSta0-service must be running
// In the LocalSystem account
//
Hwinsta = OpenWindowStation ("winsta0", FALSE,
WINSTA_ACCESSCLIPBOARD |
WINSTA_ACCESSGLOBALATOMS |
WINSTA_CREATEDESKTOP |
Winsta_enum1_tops |
WINSTA_ENUMERATE |
WINSTA_EXITWINDOWS |
WINSTA_READATTRIBUTES |
WINSTA_READSCREEN |
WINSTA_WRITEATTRIBUTES );
If (hwinsta = NULL)
Return FALSE;
//
// Set the windowstation to be winsta0
//
If (! SetProcessWindowStation (hwinsta ))
Return FALSE;

//
// Get the default desktop on winsta0
//
Hdesk = OpenDesktop ("Winlogon", 0, FALSE,
Optional top_createmenu |
Optional top_createwindow |
Optional top_enumerate |
Optional top_hookcontrol |
Optional top_journalplayback |
Optional top_journalrecord |
Optional top_readobjects |
Optional top_switchdesktop |
Optional top_writeobjects );
If (hdesk = NULL)
Return FALSE;

//
// Set the desktop to be "default"
//
If (! SetThreadDesktop (hdesk ))
Return FALSE;
PostMessage (HWND_BROADCAST, WM_HOTKEY, 0, MAKELPARAM (MOD_ALT | MOD_CONTROL, VK_DELETE ));


//
// Reset the Window station and desktop
//
If (! SetProcessWindowStation (hwinstaCurrent ))
Return FALSE;

If (! SetThreadDesktop (hsf-current ))
Return FALSE;

//
// Close the windowstation and desktop handles
//
If (! CloseWindowStation (hwinsta ))
Return FALSE;
If (! CloseDesktop (hdesk ))
Return FALSE;
Return TRUE;
}

I first tried it and found it was unsuccessful. Later, the old brother of glacier told me that OpenDesktop ("Winlogon",...) itself requires the LocalSystem permission,
As a result, register it as a service and implement the effect. I believe you can register as a service. OK, we want to implement the function.

3. Another Method
Full control of the keyboard in Dos ------- a series of BIOS-level keyboard control functions!
Http://dev.csdn.net/develop/article/7/7181.shtm
I didn't try it. I don't know if I can. Which of the following told me after the experiment?

Thank you again !!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.