windows 在 Vista 和 XP 中模拟 Control-Alt-Delete 键序列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/122367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:17:21  来源:igfitidea点击:

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

windowswinapiwindows-vista

提问by Yuval Peled

Can I simulate in C#/C++ code Control+Alt+Deletesequence in Vista? When UAC enabled/disabled? How it is done in XP?

我可以模拟在C#/ C ++代码Control+ Alt+Delete在Vista序列?何时启用/禁用 UAC?它是如何在 XP 中完成的?

Can you provide a code sample that works in Vista?

你能提供一个适用于 Vista 的代码示例吗?

回答by CSharper

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 [email protected].

用于模拟安全注意序列 (SAS) 的现有代码(大多数人将其称为 control alt delete 或 ctrl-alt-del)不再适用于 Windows Vista。微软似乎提供了一个库,可以导出一个名为 SimulateSAS() 的函数。它不是公开的,应该通过向 [email protected] 发送邮件来请求它。

There is a similar libraryavailable 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
  • 使用和不使用用户帐户控制 (UAC) 均可使用
  • 支持当前、控制台和任何终端服务器会话
  • 不需要司机
  • 调用应用程序不需要签名或具有特殊清单
  • 支持多种编程语言

Please note that this library is not free. Meanwhile you can contact [email protected]if you are interested in it.

请注意,这个库不是免费的。同时,有兴趣的可以联系[email protected]

回答by Suhas Manangi

Please use below information, "[email protected]" is deprecated and less likely to get any responses. Below information is sufficient.

请使用以下信息,“[email protected]”已被弃用,并且不太可能得到任何回复。以下信息就足够了。

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.

从 Windows 7 操作系统和随附的软件开发工具包 (SDK) 的公开可用性开始,Vista 应用程序的 SAS 功能将只能通过 Windows SDK 获得。通过电子邮件发布支持SASLIB 包,saslib 将停止使用。

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.

关于如何下载平台 SDK 的信息可以在 Microsoft 下载中心页面上的“Windows SDK for Windows 7 and .Net Framework 3.5 SP1”中找到,链接如下: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:

安装此 SDK 后,您将在 redist 目录中找到可再发行的 sas.dll:

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

\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\amd64\sas.dll

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

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

回答by Fred Merck

回答by Lou Franco

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

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

You get PostMessage from the user32 dll

你从 user32 dll 得到 PostMessage

edit: CodeProject article that has code for it

编辑:包含代码的 CodeProject 文章

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

编辑:VNC有一些关于为什么这在 Vista 中不起作用以及如何设置 UAC 以允许它的讨论。

回答by fdioff

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);