iis+vbs
■iis環境
iisマネージャー
仮想フォルダ作成
エイリアス:aaaaaaa
物理パス:c:\aaaaaaa
認証
匿名認証:管理者ユーザに変更
ハンドラーマッピング
要求パス:*.vbs
実行可能ファイル:c:\windows\system32\cscript.exe //NOLOGO %s %s
名前:適当
■ブラウザでアクセス
http://iisのサーバのIP/aaaaaaa/restart.vbs
■スクリプト restart.vbs
vbs
1Option Explicit
2
3WScript.Echo "Content-Type: text/html; charset=shift-jis"
4WScript.Echo "Access-Control-Allow-Origin: *"
5WScript.Echo
6
7'ここから処理-----------------------------------
8dim ip
9dim sname
10dim result
11
12ip = "別サーバのIP"
13sname = "Spooler"
14
15WScript.Echo "サービスの再起動を行います <br>"
16WScript.Echo "■■■最後に「result=STATE : 4 RUNNING」と出れば完了です!!!!■■■ <br>"
17WScript.Echo "サーバ:" & ip & " サービス名:" & sname & " <br>"
18
19'サービスの状態確認
20WScript.Echo "------------ <br>"
21WScript.Echo "サービスの状態を確認 <br>"
22result = ExecuteSC("\" + ip, "query", sname)
23WScript.Echo "result=" & result & " <br>"
24
25'停止して停止を待つ
26WScript.Echo "------------ <br>"
27do
28 WScript.Echo "サービスを停止 <br>"
29 result = ExecuteSC("\" + ip, "stop", sname)
30 'WScript.Echo "result=" & result & " <br>"
31
32 WScript.Sleep 1000
33
34 WScript.Echo "サービスの状態を確認 <br>"
35 result = ExecuteSC("\" + ip, "query", sname)
36 WScript.Echo "result=" & result & " <br>"
37
38 'WScript.Echo "idx=" & InStr(result, "STOPPED") & " <br>"
39loop until InStr(result, "STOPPED") <> 0
40
41'開始して開始を待つ
42WScript.Echo "------------ <br>"
43do
44 WScript.Echo "サービスを開始 <br>"
45 result = ExecuteSC("\" + ip, "start", sname)
46 'WScript.Echo "result=" & result & " <br>"
47
48 WScript.Sleep 2000
49
50 WScript.Echo "サービスの状態を確認 <br>"
51 result = ExecuteSC("\" + ip, "query", sname)
52 WScript.Echo "result=" & result & " <br>"
53
54 'WScript.Echo "idx=" & InStr(result, "RUNNING") & " <br>"
55loop until InStr(result, "RUNNING") <> 0
56
57'終了-------------------------------------------
58
59Function ExecuteSC(ip, cmd, sname)
60 dim objShell
61 dim objExec
62 dim wstr
63 dim result
64
65 result = ""
66
67 Set objShell = CreateObject("WScript.Shell")
68 Set objExec = objShell.Exec("cmd /c sc " + ip + " " + cmd + " " + sname)
69 Do Until objExec.StdOut.AtEndOfStream
70 wstr = Trim(objExec.StdOut.ReadLine())
71
72 'ステータスを抜き出す
73 if InStr(wstr, "STATE ") > 0 then
74 result = wstr
75
76 'WScript.Echo "find ok " + result
77
78 exit do
79 end if
80
81 'WScript.Echo wstr & "<br>"
82 Loop
83
84 ExecuteSC = result
85End Function
86