2012-12-21 37 views
4

如何將自定義文本添加到關閉屏幕,就像在Windows關閉前安裝更新時顯示的那些消息一樣?例如,您有一個在關機時執行的備份腳本,並且您想要像安裝更新時那樣通知備份的進度。有沒有任何命令行工具,或一些代碼庫,甚至在Windows API中的東西?如何將自定義字符串添加到Windows 7中關機屏幕顯示的消息中?

注意,這不是如何關閉一臺計算機,它是任何的方式在關機屏幕有顯示一條消息,如控制檯應用程序或消息框。這是約要麼定製現有的消息,這是有關顯示之前關機屏幕,並允許用戶取消關機或繼續,而不必等待終止程序的任何shutdown dialog

這是爲了瞭解Windows如何實現這些消息的顯示,他們都顯示有在關機的方式,以及如何添加新的消息顯示,最好用進度信息。要清楚,下面是一個截圖。

Shutdown screen

+2

ShutdownBlockReasonCreate,您可以添加自定義消息。 –

+1

ShutdownBlockReasonCreate與提問無關,請參閱其文檔並再次閱讀該問題。 –

+1

該函數在關機屏幕上顯示消息(而不是在控制檯應用程序或消息框中),這似乎是請求的內容。我想你可以在消息字符串中編碼進度計數器。你不能做的是強制關機等到你的後臺進程完成。如果用戶說「無論如何關機」,那麼系統將會關閉。 –

回答

0

如前所述,看起來wmsgapi.dll是這裏實現,但API不公開。我找到的解決方案是編寫ScreenWrite,它讀取標準輸入並將格式化文本打印到屏幕上。因此,關閉腳本可以達到類似的效果,源代碼可以在C/C++應用程序中重用。樣本截圖:

Screenshot

+0

這不是一個通用的形式。你必須下載一個額外的插件。 – riahc3

-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; 
} 
+2

-1。再次閱讀這個問題 - 它具體說它是**不**,關於如何關閉計算機並顯示消息。這是關於添加自定義文本**正常**關機屏幕。 –

0

wmsgapi.dll中有一個函數WmsgPostNotifyMessage顯示此消息。雖然沒有記錄,但不應該成爲使用中的問題。

相關問題