代码如下,以判断ie进程是否存在为例:
on error resume next set y=getobject("winmgmts:\\.\root\cimv2") set ws=createobject("wscript.shell") set x=y.execquery("select * from win32_process where name='iexplore.exe'") for each i in x msgbox "IE进程存在" wscript.quit next msgbox "IE进程不存在"
代码如下,以QQ进程是否存在为例:
on error resume next set y=getobject("winmgmts:\\.\root\cimv2") set ws=createobject("wscript.shell") set x=y.execquery("select * from win32_process where name='qq.exe'") for each i in x msgbox "发现qq进程" ws.run "123.bat" wscript.quit next msgbox "没有qq进程" ws.run "456.bat"
也可以采用如下额的方式:采用tasklist命令的方式'tasklist^|findstr /i "%DstPro%"'
Dim objws Set objws=WScript.CreateObject("wscript.shell") Do objws.Run "c:\a.vbs",,True WScript.Sleep 3000 objws.Run "tskill iexplore" objws.Run "c:\b.vbs",,True WScript.Sleep 3000 objws.Run "tskill iexplore" objws.Run "c:\c.vbs",,True WScript.Sleep 3000 objws.Run "tskill iexplore" objws.Run "c:\d.vbs",,True WScript.Sleep 3000 objws.Run "tskill iexplore" Loop