我想要一个监控进程的VBS代码,如果进程了发现1.EXE,那么就隐藏运行2.BAT,否则5分钟再检测是否存在1.EXE
如果发现1.EXE并执行了2.BAT后不用退出,5分钟后继续检测,如果没发现1.EXE也是过5分钟后再检测,如此反复...
如果发现1.EXE并执行了2.BAT后不用退出,5分钟后继续检测,如果没发现1.EXE也是过5分钟后再检测,如此反复
展开
3个回答
展开全部
Do
If FindProcess("1.exe") Then
RunProcess "2.bat"
WScript.Sleep 5 * 60 * 1000 '转换成秒数
End If
Loop
Function FindProcess(s)
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = '" & s & "'")
For Each objProcess In colProcessList
FindProcess = True
Exit Function
Next
End Function
Sub RunProcess(s)
Set wsh = CreateObject("WScript.Shell")
wsh.Run s, vbHide
Set wsh = Nothing
End Sub
If FindProcess("1.exe") Then
RunProcess "2.bat"
WScript.Sleep 5 * 60 * 1000 '转换成秒数
End If
Loop
Function FindProcess(s)
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = '" & s & "'")
For Each objProcess In colProcessList
FindProcess = True
Exit Function
Next
End Function
Sub RunProcess(s)
Set wsh = CreateObject("WScript.Shell")
wsh.Run s, vbHide
Set wsh = Nothing
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
on error resume next
set process = getobject("winmgmts:\\.\root\cimv2").execquery("select * from win32_process")
set shell=createobject("wscript.shell")
public function find(byval prv)
For Each i In process
If lcase(i.caption)=lcase(prv) Then find=i.caption:exit for
Next
end function
do
if find("1.exe") <> "" then shell.run "2.bat"
wscript.sleep 300000
loop
set process = getobject("winmgmts:\\.\root\cimv2").execquery("select * from win32_process")
set shell=createobject("wscript.shell")
public function find(byval prv)
For Each i In process
If lcase(i.caption)=lcase(prv) Then find=i.caption:exit for
Next
end function
do
if find("1.exe") <> "" then shell.run "2.bat"
wscript.sleep 300000
loop
追问
批处理好像没有隐藏
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
求解中....
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询