在踹Ruby on Rails另一個container-Mongrel(匈牙利的),結果可以做成Windows的服務(Service),可以啟動終止,但移除的方法卻沒講,只好找來下面的VBScript進行移除,這工具好用…但也粉危險。
Const title = "服務移除工具"
Set oWS = CreateObject("Wscript.Shell")
sService = inputbox("請輸入欲移除的服務名稱",title,"Service_name")
If sService = "" then
msgbox "程式停止執行,沒有移除任何服務。", vbInformation, title
wscript.quit
End If
'//確認是否移除服務
result = MsgBox ("即將移除 " & sService & " 這個服務,您確定嗎?", vbQuestion + vbYesno, title)
If result = vbNo Then
Msgbox "程式停止執行,沒有移除任何服務。", vbInformation, title
wscript.quit
End If
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'//檢查要移除的服務是否存在
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name = '" & sService & "' or displayName = '" & sService & "'")
If colListOfServices.count > 0 Then
For Each objService In colListOfServices
objService.StopService()
'//暫停 5 秒鐘,以確保服務已停止
wscript.Sleep 5000
objService.Delete()
Msgbox sService & " 已移除或已被標示成刪除。", vbInformation, title
Next
Else
Msgbox "找不到 " & sService & " 這個服務。", vbInformation, title
End If