環境:當某程式(比如QQ)當掉之後,要能自動起來;現在設定為隻要QQ.exe程式個數為0,5秒後QQ.exe就直接自動啟動。
備忘之用,解決了監控伺服器自動當掉問題。
dim i
strComputer = "."
do while true
i=0
Set wbemServices = Getobject("winmgmts:\\" & strComputer)
Set objWMIService = GetObject ("winmgmts:\\" & strComputer & "\root\cimv2")
Set cmd=wscript.createobject("wscript.shell")
Set wbemObjectSet = wbemServices.InstancesOf("Win32_Process")
For Each wbemObject In wbemObjectSet
if wbemObject.Name="Foxmail.exe" then i=1
Next
if i=0 then
Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'tt.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
cmd.run "cmd /c start C:\Foxmail\Foxmail.exe",0
end if
WScript.Sleep(5*1000)
Loop