Simulate Control-Alt-Delete key sequence in Vista and XP

こ雲淡風輕ζ 提交于 2019-12-04 07:07:30

Existing code to simulate the Secure Attention Sequence (SAS), which most people refer to as control alt delete or ctrl-alt-del, no longer works in Windows Vista. It seems that Microsoft offers a library that exports a function called SimulateSAS(). It is not public and one is supposed to request it by sending a mail to saslib@microsoft.com.

There is a similar library available with the following features:

  • Works both with and without User Account Control (UAC)
  • Supports current, console and any Terminal Server session
  • Does not need a driver
  • The calling application does not need to be signed or have a special manifest
  • Supports multiple programming languages

Please note that this library is not free. Meanwhile you can contact info@simulatesas.com if you are interested in it.

Please use below information, "saslib@microsoft.com" is deprecated and less likely to get any responses. Below information is sufficient.

Beginning with the public availability of the Windows 7 Operating System and accompanying Software Development Kit (SDK), SAS functionality for Vista applications will only be available through the Windows SDK. The release support through email of the SASLIB package, and the saslib will be discontinued.

Information on how to download the platform SDK can be found on the Microsoft Download Center page for the “Windows SDK for Windows 7 and .Net Framework 3.5 SP1” at the following link: http://www.microsoft.com/downloads/details.aspx?FamilyID=c17ba869-9671-4330-a63e-1fd44e0e2505&displaylang=en.

After you install this SDK you will find the redistributable sas.dll in the redist directory:

\Program Files\Microsoft SDKs\Windows\v7.0\redist\x86\sas.dll

\Program Files\Microsoft SDKs\Windows\v7.0\redist\amd64\sas.dll

\Program Files\Microsoft SDKs\Windows\v7.0\redist\ia64\sas.dll

PostMessage(HWND_BROADCAST, WM_HOTKEY, 0, MAKELONG(MOD_ALT | MOD_CONTROL, VK_DELETE));

You get PostMessage from the user32 dll

edit: CodeProject article that has code for it

edit: There is some discussion from VNC on why that won't work in Vista and how to set up UAC to allow it.

You have to call next code from service process only

HDESK desktop = OpenDesktopW(L"Winlogon", 0, TRUE,
    DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW | DESKTOP_ENUMERATE | 
    DESKTOP_HOOKCONTROL | DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
    DESKTOP_SWITCHDESKTOP | GENERIC_WRITE);
int result = SetThreadDesktop(desktop);
if (result)
{
    HMODULE sasdll = LoadLibraryA("sas.dll");
    if (sasdll)
    {
        typedef void(__stdcall * SendSAS_t)(BOOL);
        SendSAS_t sendSAS = (SendSAS_t)GetProcAddress(sasdll, "SendSAS");
        if (sendSAS)
            sendSAS(FALSE);
    }
}
CloseDesktop(desktop);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!