环境:当某程序(比如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