如何用VBS检测进程程序是否运行

来源:百度知道 编辑:UC知道 时间:2024/05/24 02:11:17
我想用VBS检测A程序是否在运行
如果在就不执行B程序.
不在运行就执行B程序
然后在关闭B程序

程序已经调试过 (vbs的哦~) ok~
do
Set Of = CreateObject("Scripting.FileSystemObject")
set ws=createobject("wscript.shell")
dim OK,oShell
OK=False
set bag=getobject("winmgmts:\\.\root\cimv2")
set pipe=bag.execquery("select * from win32_process where name='A程序进程名'")
For Each id In pipe
OK = True
Next
If not OK Then
ws.run"B程序的路径",0,ture
wscript.sleep 3000
ws.run"%Comspec% /c"&"tskill B程序名(要去掉.exe)",0,ture
end if
wscript.sleep 3000
loop

用批处理写就好了,vbs我不懂...
试试看:
dim str1,str2
str1="cmd /c tasklist|find /i ""A程序进程"" || start """" ""B程序路径"""
wscript.createobject("wscript.shell").run str1,0
WScript.Sleep 3000
str2="cmd /c tasklist|find /i ""B程序进程"" && taskkill /im "