Domanda

How to simulate this ctrl alt del so that it will work ?

My code is as follows:

INPUT Input; /* Generate a "key down" */

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));
È stato utile?

Soluzione

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;

}

Altri suggerimenti

CTRL+ALT+DEL is the secure attention sequence (SAS) and you can't fake it with SendInput. The SendSAS function is what you need to call.

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top