用批处理或VBS做个进程检测。请教高手
比如有3个程序 A.EXE和B.EXE与C.EXE。运行批处理后启动A.EXE后过5分钟检测进程。如果检测到A.EXE进程时关闭B.EXE自动运行C.EXE。最后退出批处理。有高手能指点下吗?
'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
@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