Для Windows XP, поскольку SendSAS недоступен:
#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;
}