2016-12-07 58 views
0

我的c#應用程序中有一個重啓按鈕。
這是我的代碼片段:
System.Diagnostics.Process.Start("shutdown.exe", "-r -t 15");通過批量重啓系統時隱藏Windows消息

我的問題是,我得到一個默認的Windows消息: enter image description here

我知道,我可以通過-c "some string"改變消息的內容,
我怎樣才能完全刪除它? (我有我自己的留言來顯示)

謝謝!

+0

用'的Windows API '在[相關文章]中描述的調用(http://stackoverflow.com/questions/102567/how-to-shut-down-the-computer-from-c-sharp)。 –

回答

0

你可以試試:

System.Diagnostics.Process.Start("shutdown.exe", "-r -t 15 -f"); 

-f強制運行的應用程序關閉而沒有預先警告用戶。 -t參數在爲-t參數指定大於0的值時隱含。

+0

感謝您的答案,但它沒有幫助。我仍然收到相同的消息框 – nafarkash

+1

您可以嘗試 'System.Threading.Thread.Sleep(15000); System.Diagnostics.Process.Start(「shutdown.exe」,「-r -t 0 -f」);' 這是否有幫助? –

0

感謝@nick_gabpe我設法繞過了這個問題。
不知道這是否是最巧妙的答案,但它的工作原理..

我有「立即重新啓動」按鈕,然後我用一個BackgroundWorker我的問題一個消息:

public static void RebootMachine() 
    { 

     BackgroundWorker worker = new BackgroundWorker();    
     worker.DoWork += (o, ea) => 
     { 
      System.Threading.Thread.Sleep(15000); 
     }; 
     worker.RunWorkerCompleted += (o, ea) => 
     {     
      System.Diagnostics.Process.Start("shutdown.exe", "-f -r -t 0"); 
     };    

     worker.RunWorkerAsync(); 

     DialogResult result = MsgBox.Show("The device will be initialized in 15 seconds", 
      "Restarting device", MsgBox.Buttons.RestartNow, MsgBox.Icon.Info, MsgBox.AnimateStyle.FadeIn); 

     if (result == DialogResult.Yes) 
     { 
      System.Diagnostics.Process.Start("shutdown.exe", "-f -r -t 0");  
     } 

    } 
+0

這裏的BackgroundWorker有什麼意義? –

+0

只需要在背景上使用另一個線程,以便我的UI仍然可以工作,這是我頭腦中首先想到的。你有更好的方法來做到這一點? – nafarkash

+0

代碼*實際上是否執行Thread.Sleep,或者這只是您在那裏做實際工作的代碼的演示?我不清楚爲什麼當你強制立即關閉時,你關心你的UI保持響應。 –