如何将自定义文本添加到关机屏幕,例如 Windows 在关机前安装更新时显示的那些消息?例如,您有一个在关机时执行的备份脚本,并且您想通知备份的进度,就像 Windows 在安装更新时所做的那样。是否有任何命令行工具,或某些代码库,甚至 Windows API 中的某些内容?
请注意,这不是关于如何关闭一台计算机,这是不是对什么方式来显示关机屏幕,如控制台应用程序或消息框的消息出现。这是不是对任何自定义现有的消息,这是没有任何关机对话框该节目之前关闭屏幕,并允许用户取消关机或继续,而不必等待终止的程序。
这是关于了解 Windows 如何实现这些消息的显示,它们在关闭时的显示方式,以及如何添加要显示的新消息,最好是带有进度信息。为了清楚起见,下面是屏幕截图。

Lic*_*son -1
这是一个可以通过消息关闭计算机的 C++ 代码。
#include <windows.h>
#pragma comment( lib, "advapi32.lib" )
BOOL MySystemShutdown( LPTSTR lpMsg )
{
HANDLE hToken; // handle to process token
TOKEN_PRIVILEGES tkp; // pointer to token structure
BOOL fResult; // system shutdown flag
// Get the current process token handle so we can get shutdown
// privilege.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return FALSE;
// Get the LUID for shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);
// Cannot test the return value of AdjustTokenPrivileges.
if (GetLastError() != ERROR_SUCCESS)
return FALSE;
// Display the shutdown dialog box and start the countdown.
fResult = InitiateSystemShutdown(
NULL, // shut down local computer
lpMsg, // message for user
30, // time-out period, in seconds
FALSE, // ask user to close apps
TRUE); // reboot after shutdown
if (!fResult)
return FALSE;
// Disable shutdown privilege.
tkp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);
return TRUE;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3001 次 |
| 最近记录: |