模拟ctrl+alt+delete三键解锁server端

  --------------------------------------------------------------------------------  
  www.hackbase.com   阅读:   时间:2005-1-13   5:05:23   来源:www.hackbase.com      
  来源:www.zahui.com  
   
  在我们编写远程控制软件的时候,我们会发现要想解锁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  
  我没有试验,不知道可否,哪位大哥试验后告诉我一声  
   
  在此再次感谢黄鑫大哥!!  
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值