LoginSignup
3

More than 5 years have passed since last update.

Windowsをコマンドで再起動する方法

Last updated at Posted at 2016-01-12

はじめに

定期的にWindows Server 2008 R2のサーバを日次再起動するジョブ(Powershellで「Restart-Computer -ComputerName %remotehost% -Force」を実行)を作成したところ、シャットダウン途中で固まってしまう事象が1ヶ月に1回くらい発生して悩まされました。
shutdown.exeを用いた場合は、シャットダウン途中で固まることがありませんでした。
どうもネットワーク共有接続された状態だとうまくいかないようでした。
Powershellの「-Force」はコンソールやターミナルセッションの強制ログオフには対応していますが、ネットワーク共有接続の切断には対応していないのかな?

再起動/シャットダウン方法を整理します。

再起動

■shutdown.exeを用いた場合

 shutdown.exe /r /m \%remotehost% /t 3 /c "コメント"

 ※オプション
  /r:再起動
  /m \コンピューター名:再起動対象
  /t 3:3秒後に強制(/f)実行
  /c コメント:文字数制限があるのでshutdown.exe /?で確認すること

■Restart-Computerコマンドレットを用いた場合

 # ネットワーク共有接続の強制切断
 net session /delete /y
 # 再起動
 Restart-Computer -ComputerName %remotehost% -Force

シャットダウン

■shutdown.exeを用いた場合

 shutdown.exe /s /m \%remotehost% /t 3 /c "コメント"

 ※オプション
  /s:シャットダウン
  /m \コンピューター名:再起動対象
  /t 3:3秒後に強制(/f)実行
  /c コメント:文字数制限があるのでshutdown.exe /?で確認すること

■Restart-Computerコマンドレットを用いた場合

 # ネットワーク共有接続の強制切断
 net session /delete /y
 # シャットダウン
 Stop-Computer -ComputerName %remotehost% -Force

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3