2016-04-03 50 views
1

我熟悉shutdown /a-a,但只有在關機前有計時器纔有效。取消PC關機 - 無時間段

有沒有辦法讓我寫一個批處理文件,即使用戶手動關機,也會停止關機過程?

+1

當我谷歌'窗戶阻止關機'我得到了很多結果,他們都沒有爲你工作? –

+0

所有即時通訊都是這種類型:'C:\ WINDOWS \ system32 \ shutdown.exe -a' 但正如我所說的,它只在關機由定時器完成或關機時才工作 - t 200 我不能使用它來停止當我通過windows gui按下關機按鈕時關機。 –

+1

我認爲你可以 - 你只需要快速運行它,而關機正在運行。你確切的情況是什麼,你可以添加更多的細節?例如,管理員可以使用註冊表來防止非管理員用戶關閉機器。這不是一個選項嗎? –

回答

0

此vbscript可以創建桌面的快捷方式,詢問您是否要休眠計算機。

當然,您可以將其更改爲重新引導或關閉。

Option Explicit 
Dim MyScriptPath 
MyScriptPath = WScript.ScriptFullName 
Call Shortcut(MyScriptPath,"Hibernate the computer") 
Call AskQuestion() 
'********************************************************************************************** 
Sub Shortcut(PathApplication,Name) 
    Dim objShell,DesktopPath,objShortCut,MyTab 
    Set objShell = CreateObject("WScript.Shell") 
    MyTab = Split(PathApplication,"\") 
    If Name = "" Then 
     Name = MyTab(UBound(MyTab)) 
    End if 
    DesktopPath = objShell.SpecialFolders("Desktop") 
    Set objShortCut = objShell.CreateShortcut(DesktopPath & "\" & Name & ".lnk") 
    objShortCut.TargetPath = Dblquote(PathApplication) 
    ObjShortCut.IconLocation = "%SystemRoot%\system32\SHELL32.dll,-28" 
    objShortCut.Save 
End Sub 
'********************************************************************************************** 
Sub AskQuestion() 
    Dim Question,Msg,Title 
    Title = "Hibernate the computer by Hackoo 2016" 
    Msg = "Are you sure to Hibernate the computer now ?"& Vbcr &_ 
    "If yes, then click [YES] button "& Vbcr &_ 
    "If not, then click [NO] button" 
    Question = MsgBox (Msg,VbYesNo+VbQuestion,Title) 
    If Question = VbYes then 
     Call Run_Hibernate() 
    else 
     WScript.Quit() 
    End if 
End Sub 
'********************************************************************************************** 
Function DblQuote(Str) 
    DblQuote = Chr(34) & Str & Chr(34) 
End Function 
'********************************************************************************************** 
Sub Run_Hibernate() 
    Dim ws,Command,Execution 
    Set ws = CreateObject("wscript.Shell") 
    Command = "Cmd /c %windir%\System32\rundll32.exe powrprof.dll,SetSuspendState Hibernate" 
    'Command = "Cmd /c Shutdown -s -t "& N &" -c "& DblQuote("Save your work because your PC will shut down in "& N &" seconds") 
    Execution = ws.run(Command,0,True) 
End sub 
'**********************************************************************************************