在我们编写远程控制软件的时候,我们会发现要想解锁server端我们就得发送这三个键的虚拟。
下面我说一下解决过程
1.一开始,决定通过keybd_event()来模拟键盘
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); 发现只能模拟ctrl+alt两个键的效果,然而其他的两个键的都可以模拟比如win+d。不知道是不是keybd_event()只能模拟两键还是因为ctrl+alt+delete的特殊性,望高手告之,在此谢过。
2.运用PostMessage(HWND_BROADCAST, WM_HOTKEY, 0, MAKELONG(MOD_ALT | MOD_CONTROL, VK_DELETE));来发送虚拟键盘,但是在winNT以后的系统里我们还有很多事情要做,比如:OpenDesktop()、OpenInputDesktop()、GetThreadDesktop()、SetThreadDesktop()、CloseDesktop()、GetUserObjectInformation()
代码如下:
#include "windows.h"BOOL simulateAltControlDel();void main(){ simulateAltControlDel();}BOOL simulateAltControlDel(){ HDESK hdeskCurrent; HDESK hdesk; HWINSTA hwinstaCurrent; HWINSTA hwinsta; // // Save the current Window station // hwinstaCurrent = GetProcessWindowStation(); if (hwinstaCurrent == NULL) return FALSE; // // Save the current desktop // hdeskCurrent = GetThreadDesktop(GetCurrentThreadId()); if (hdeskCurrent == 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_ENUMDESKTOPS | 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, DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW | DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL | DESKTOP_JOURNALPLAYBACK | DESKTOP_JOURNALRECORD | DESKTOP_READOBJECTS | DESKTOP_SWITCHDESKTOP | DESKTOP_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(hdeskCurrent)) return FALSE;
// // Close the windowstation and desktop handles // if (!CloseWindowStation(hwinsta)) return FALSE; if (!CloseDesktop(hdesk)) return FALSE; return TRUE;}
偶一开始试验了发现不成功,后来冰河大哥告诉我说OpenDesktop("Winlogon", ......)本身需要LocalSystem权限,果然如此,把它注册成服务,然后效果实现。相信如何注册成服务不用我说了吧。ok,我们想要的功能实现了。
3.还有一种方法Dos下键盘的完全控制 ------- 一系列的BIOS级别的键盘控制函数!http://dev.csdn.net/develop/article/7/7181.shtm我没有试验,不知道可否,哪位大哥试验后告诉我一声
在此再次感谢黄鑫大哥!!
本文地址:http://com.8s8s.com/it/it24586.htm