ip="47.96.160.63"
port="10010"
Const INTERVA = 5  '检测间隔
ps_str="Mqtt_AGI.exe"

Set ws = CreateObject("Wscript.Shell") 

do while true
    if CheckProcess(ps_str)=0 then
        ws.run "cmd /c .\Mqtt_AGI.exe"&" "&ip&" "&port,vbhide
    end if
    wscript.sleep 1000 * INTERVA  '检测间隔
loop

 
Function CheckProcess(str_s)
Dim WMI,Objs,Process,Obj
CheckProcess=0
Set WMI=GetObject("WinMgmts:")
Set Objs=WMI.InstancesOf("Win32_Process")
Process=""
'遍历所有在运行的进程
For Each Obj In Objs
Process = Obj.Description
If Process = str_s Then
CheckProcess=1
Exit For '发现所需进程时退出遍历
end if
Next
End Function


Function find_yn(str_s)   '查找进程是否存在，不存在返回0
    Dim re,ms,m
    find_yn = 0
    set re = New RegExp
    re.Global = True
    re.MultiLine = True 
    re.Pattern = "^Mqtt_AGI.exe"  '测试查找进程
    set ms = re.Execute(str_s)
    For Each m In ms
        'msgbox m
        find_yn = find_yn + 1
    Next
End Function