批处理和VBS检测进程是否存在并执行相关操作
批处理检测进程是否存在;这个我用来检测文化进程是否存在,因为是绿色版的,很容易被关闭,所以需要检测。
tasklist /nh|find /i "ClientOfWatcher.exe"
if ERRORLEVEL 1 (start C:\watcher\ClientOfWatcher.exe) else (exit)
option Explicit
dim wmi,proc,procs,proname,flag,WshShell
Do
proname="ClientOfWatcher.exe" '需要监测的服务进程的名称,自行替换这里的记事本进程名
set wmi=getobject("winmgmts:{impersonationlevel=impersonate}!\\.\root\cimv2")
set procs=wmi.execquery("select * from win32_process")
flag=true
for each proc in procs
if strcomp(proc.name,proname)=0 then
flag=false
exit for
end if
next
set wmi=nothing
if flag then
Set WshShell = Wscript.CreateObject("Wscript.Shell")
WshShell.Run ("C:\Watcher\ClientOfWatcher.exe")
end if
wscript.sleep 50000 '检测间隔时间,这里是50秒
loop