シャットダウンのサンプル

Windowsをシャットダウンする為のサンプルです。

'' shut.vbs
'' Windows XP シャットダウンスクリプト
''
'' 第一引数で指定した時間を経過後、
'' Windows を終了する。
'' shutdown.exeを使っているので、たぶんXP専用。

Dim WSHArguments ' 引数の取得用
Dim WshShell
Dim strTime ' 時間
Dim strProgram ' シャットダウンコマンド
Dim strTimerOption ' 時間セット用オプション
Dim strMessageOption ' メッセージ用オプション

''shutdown.exeを使う。
strProgram = """C:\WINDOWS\system32\SHUTDOWN.EXE"""

Set WSHArguments = WScript.Arguments
Set WshShell = Wscript.CreateObject("Wscript.Shell")

'' 引数で指定されれば、その時間(分)経過後に終了する。
If WSHArguments.Count = 1 Then
 strTime = WSHArguments.item(0)
Else
'' 引数で指定されない場合は、5分後に終了する。
 strTime = 5
End If

''時間をセット
strTimerOption =" -t " & strTime * 60

''メッセージをセット
strMessageOption=" -c """ & strTime & "分後シャットダウンします。 """

''shutdown.exeを実行
WshShell.Run(strProgram & " -s" & strTimerOption & strMessageOption)

Set WshShell = nothing
Set WSHArguments = nothing

Wscript.Quit


Bookmark this on Yahoo Bookmark
Bookmark this on Google Bookmarks
Share on LinkedIn
LINEで送る
Pocket