![](/img/trans.png)
[英]how to shutdown-restart-hibernate-stand by-log off computer using Process.Start()?
[英]Start executing an exe file in windows, restart computer, and pick up where the process left off
這是可能嗎? 如果是這樣,怎么樣? 流程將是這樣的:
private void DoStuff()
{
// Do some stuff
RestartPc();
}
private void RestartPc()
{
Process.Start("shutdown", "/r /t 0");
}
// Call this when the PC is restarted:
private void DoStuffAfterRestart() {}
所有這些代碼都是一個Windows服務 ,所以如果 pc重新啟動並且直接進入DoStuffAfterRestart
,那么告訴OnStart
方法跳過DoStuff
的“最佳”方法是什么,因為服務將被設置為自動啟動。
Idk如果有特殊的方法,但我會有一個解決方案:
將您的程序添加到自動啟動。 編輯:像@PTwr指出你不應該使用正常的自動啟動。 請改用Run once注冊表項 。
將代碼更改為如下所示:
public static void main(string[] args)
{
var x = loadState();
if(x == null)
DoStuff();
else
DoStuffAfterRestart();
}
private void DoStuff()
{
// Do some stuff
SafeState();
RestartPc();
}
// Call this when the PC is restarted:
private void DoStuffAfterRestart() {}
在安全/加載方法中,您必須將某些內容寫入文件/注冊表以記住您當前的狀態
通過保存你的“當前位置”,你可以“記住”你最后一次去哪里並在重啟后做正確的事情。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.