用批处理或VBS做个进程检测。请教高手
比如有3个程序A.EXE和B.EXE与C.EXE。运行批处理后启动A.EXE后过5分钟检测进程。如果检测到A.EXE进程时关闭B.EXE自动运行C.EXE。最后退出批处理...
比如有3个程序 A.EXE和B.EXE与C.EXE。运行批处理后启动A.EXE后过5分钟检测进程。如果检测到A.EXE进程时关闭B.EXE自动运行C.EXE。最后退出批处理。有高手能指点下吗?
展开
2个回答
展开全部
'VBS代码如下
PathA = "C:\A.EXE"
PathB = "C:\B.EXE"
PathC = "C:\C.EXE"
Set oWsh = CreateObject("WScript.Shell")
oWsh.Run PathA
WScript.Sleep 300000
For each Process in GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_process")
If Process.Name = "A.EXE" Then
For each ProcessB in GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_process")
If ProcessB.Name = "B.EXE" Then
ProcessB.Terminate
End If
Next
End If
Next
oWsh.Run PathC
PathA = "C:\A.EXE"
PathB = "C:\B.EXE"
PathC = "C:\C.EXE"
Set oWsh = CreateObject("WScript.Shell")
oWsh.Run PathA
WScript.Sleep 300000
For each Process in GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_process")
If Process.Name = "A.EXE" Then
For each ProcessB in GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_process")
If ProcessB.Name = "B.EXE" Then
ProcessB.Terminate
End If
Next
End If
Next
oWsh.Run PathC
展开全部
@echo off
start "" "a.exe"
ping -n 300 127.1>nul
tasklist|(>nul findsrt /i "a.exe"&&(taskkill /f /im b.exe&start "" "c.exe"))
运行 a.exe
ping,大概延时也是5分钟左右
检测到a时,关闭b并且运行c后退出
PS:如果检测不到a,则直接退出
如果想让批处理循环检测,加多个goto就行了
@echo off
start "" "a.exe"
:loop
ping -n 300 127.1>nul
tasklist|(>nul findsrt /i "a.exe"&&(taskkill /f /im b.exe&start "" "c.exe"&exit))
goto loop
start "" "a.exe"
ping -n 300 127.1>nul
tasklist|(>nul findsrt /i "a.exe"&&(taskkill /f /im b.exe&start "" "c.exe"))
运行 a.exe
ping,大概延时也是5分钟左右
检测到a时,关闭b并且运行c后退出
PS:如果检测不到a,则直接退出
如果想让批处理循环检测,加多个goto就行了
@echo off
start "" "a.exe"
:loop
ping -n 300 127.1>nul
tasklist|(>nul findsrt /i "a.exe"&&(taskkill /f /im b.exe&start "" "c.exe"&exit))
goto loop
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询