VBS判断某个进程存在与否?

2024-12-14 05:50:19
推荐回答(3个)
回答1:

以百度hi进程为例:
'═════代═══码═══开═══始═════
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='BaiduHi.exe'")
for each i in x
msgbox "BaiduHi进程存在"
wscript.quit
next
msgbox "BaiduHi进程不存在"
'═════代═══码═══结═══束═════

将其中的BaiduHi替换为你要检测的进程名。

回答2:

以qq为例吧,嘻嘻.楼主如若要查询其它进程,请用那个进程的进程名替换掉下面出现qq.exe的地方
‘------------------------VBS团队-------------------------
dim obj
dim matches
set obj = getobject("winmgmts:")
set matches = obj.execquery("select * from win32_process")
for each match in matches
if lcase(match.name) = "qq.exe" then
msgbox "QQ正在运行。。。"
WScript.Quit
else
msgbox "QQ没有运行!"
WScript.Quit
End if
next
set obj = nothing
’------------------------VBS团队-------------------------

回答3:

程序已经测试过 ok~

do
Set Of = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
dim OK,oShell
OK=False
set bag=getobject("winmgmts:\\.\root\cimv2")
set pipe=bag.execquery("select * from win32_process where name='notepad.exe'")
For Each id In pipe
OK = True
Next
If not OK Then
objShell.open("d:\")
end if
wscript.sleep 60000
loop