VBScriptを使用してWindowsボックスを強制的に再起動する方法は?

StackOverflow https://stackoverflow.com/questions/188636

  •  06-07-2019
  •  | 
  •  

質問

Windowsを強制的に再起動する方法を見つけようとしていますが、問題が発生しています。試しました

Set OpSysSet = GetObject("winmgmts:{authenticationlevel=Pkt," _
     & "(Shutdown)}").ExecQuery("select * from Win32_OperatingSystem where "_
     & "Primary=true")
for each OpSys in OpSysSet
    retVal = OpSys.Reboot()
next

shutdown -f -r コマンドも使用しようとしましたが、どちらの場合も応答が得られない場合があり、再試行すると" Action could not completeというエラーが表示されますシステムがシャットダウンしているためです」どれだけ長く放置してもシャットダウンしませんが、それでも新しいプログラムを起動でき、 shutdown -a を実行しても同じエラーが発生します。スクリプトを使用してWindowsを強制的に再起動するにはどうすればよいですか?

役に立ちましたか?

解決

交換を試してください:

retVal = OpSys.Reboot()

with:

retVal = OpSys.Win32Shutdown(6)

他のヒント

まあ、これはVBScriptを使用します-正直なところ、あなたがやろうとしているのと同じコマンドラインシャットダウンを呼び出します。私はそれをテストしましたが、動作します。

Dim oShell 
Set oShell = CreateObject("WScript.Shell")

'restart, wait 5 seconds, force running apps to close
oShell.Run "%comspec% /c shutdown /r /t 5 /f", , TRUE

どのOSを実行していますか?このテストはXPに対するものでした。サーバーOSにシャットダウンコードが必要かどうか疑問に思います...

MicrosoftのSysinternalsからpsShutdownコマンドラインユーティリティを試すこともできます。 http://technet.microsoft.com/en-us/sysinternals/bb897541。 aspx

'*********************************************************

Option Explicit

Dim objShell

Set objShell = WScript.CreateObject("WScript.Shell")

objShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 0"

'*********************************************************

この小さなスクリプトは、0秒後にローカルコンピューターを再起動します。

Set Reset= WScript.CreateObject ("WScript.Shell")

Reset.run "shutdown -r -t 00", 0, True

または..

Shell "shutdown -r -t 00"   ' for restart

Shell "shutdown -s -t 00"  ' for Shutdown

Shell "shutdown -l -t 00"   ' for log off

Shell "shutdown -a -t 00"  ' for abort
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top