Send Ctrl Alt Del via INPUT Structure not working?

How can I simulate this ctrl alt del to make it work?

My code looks like this:

INPUT Input; / * Generate a down key * /

Input.type  = INPUT_KEYBOARD;
Input.ki.dwFlags  = KEYEVENTF_SCANCODE; 
Input.ki.wScan=29;
Input.ki.dwExtraInfo=0;
Input.ki.wVk=0;
Input.ki.time=0;
SendInput(1, &Input, sizeof(Input));


Input.type  = INPUT_KEYBOARD;
Input.ki.dwFlags  = KEYEVENTF_SCANCODE; 
Input.ki.wScan=56;
Input.ki.dwExtraInfo=0;
Input.ki.wVk=0;
Input.ki.time=0;
SendInput(1, &Input, sizeof(Input));


Input.type  = INPUT_KEYBOARD;
Input.ki.dwFlags  = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_SCANCODE; 
Input.ki.wScan=83;
Input.ki.dwExtraInfo=0;
Input.ki.wVk=0;
Input.ki.time=0;
SendInput(1, &Input, sizeof(Input));


Input.type  = INPUT_KEYBOARD;
Input.ki.dwFlags  = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP; 
Input.ki.wScan=29;
Input.ki.dwExtraInfo=0;
Input.ki.wVk=0;
Input.ki.time=0;
SendInput(1, &Input, sizeof(Input));


Input.type  = INPUT_KEYBOARD;
Input.ki.dwFlags  = KEYEVENTF_SCANCODE  | KEYEVENTF_KEYUP; 
Input.ki.wScan=56;
Input.ki.dwExtraInfo=0;
Input.ki.wVk=0;
Input.ki.time=0;
SendInput(1, &Input, sizeof(Input));


Input.type  = INPUT_KEYBOARD;
Input.ki.dwFlags  = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_SCANCODE  | KEYEVENTF_KEYUP; 
Input.ki.wScan=83;
Input.ki.dwExtraInfo=0;
Input.ki.wVk=0;
Input.ki.time=0;
SendInput(1, &Input, sizeof(Input));

      

+3


source to share


2 answers


For Windows XP, since SendSAS is not available:



#define _WIN32_WINNT 0x0500

#include <windows.h>
#include <winwlx.h>

#include <stdio.h>

BOOL CALLBACK parents(HWND hwnd, LPARAM dummy);

HWND saswindow = NULL;

int main(int argc, char ** argv) {

  HDESK h;

  HWINSTA hw;

  DWORD err;

  hw = OpenWindowStation("winsta0", FALSE, GENERIC_ALL);

  if (!hw) {

    printf("Error %u calling OpenWindowStation.\n", GetLastError());

    return 1;

  }

  if (!SetProcessWindowStation(hw)) {

    printf("Error %u calling SetProcessWindowStation.\n", GetLastError());

    return 1;

  }

  h = OpenDesktop("Winlogon", 0, FALSE, GENERIC_ALL);

  if (!h) {

    printf("Error %u calling OpenDesktop.\n", GetLastError());

    return 1;

  }

  if (!EnumDesktopWindows(h, parents, 0)) {

    err = GetLastError();

    if (err != 0) {

      printf("Error %u enumerating top-level windows.\n", err);

      return 1;

    }

  }

  if (saswindow == NULL) {

    printf("SAS window not found.\n");

    return 1;

  }

  if (!PostMessage(saswindow, WLX_WM_SAS, WLX_SAS_TYPE_CTRL_ALT_DEL, 0)) {

    printf("Error %u posting message.\n", GetLastError());

    return 1;

  }

  return 0;

}

BOOL CALLBACK parents(HWND hwnd, LPARAM dummy) {  

  static int n;

  static char wintext[16];

  n = GetWindowText(hwnd, wintext, sizeof(wintext));

  if (n == 0) return TRUE;

  if (strcmp(wintext, "SAS window") != 0) return TRUE;

  saswindow = hwnd;

  SetLastError(0);

  return FALSE;

}

      

+4


source


CTRL + ALT + DEL is a Safe Attention Sequence (SAS) and you cannot fake it with SendInput

. The function SendSAS

is what you need to call.



However, this is only available for Windows 7. For older versions of Windows, if I remember correctly, you need to request a special library from MS to create SAS. My memory is failing, but I think it is called SASLIB. There is also a commercial product known as SasLibEx that does the job. Another possibility if you need to support older versions of Windows is to look at the VNC source code to see how they do it.

+5


source







All Articles