監控程序運行狀態

環境:當某程序(比如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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章