Batch file vbs检查bat是否正在运行

Batch file vbs检查bat是否正在运行,batch-file,vbscript,Batch File,Vbscript,我有一个批处理文件,在计算机中运行,并检查一些东西-Start.bat 我想编写VBS,在后台检查批处理文件是否正在运行。如果跑,什么也不做。如果没有,就跑 这段代码总是告诉我批处理文件正在运行,但他没有 Set WshShell = WScript.CreateObject("WScript.Shell") Do Set locator = CreateObject("WbemScripting.SWbemLocator") Set service = locator.Conn

我有一个批处理文件,在计算机中运行,并检查一些东西-Start.bat

我想编写VBS,在后台检查批处理文件是否正在运行。如果跑,什么也不做。如果没有,就跑

这段代码总是告诉我批处理文件正在运行,但他没有

Set WshShell = WScript.CreateObject("WScript.Shell")
Do
    Set locator = CreateObject("WbemScripting.SWbemLocator")
    Set service = locator.ConnectServer()
    Set props = service.ExecQuery _
       ("select name, description from Win32_Process where name = 'Start.bat'")
    num = props.Count


    If num > 0 Then
      WScript.Echo "Program is running"
    Else
       WScript.Echo "Program is not running" 
    End If


    Set WSHShell = Nothing
    Wscript.Sleep 1000
loop

更改批处理文件的名称,
Start
是一个命令@Compo仍然不起作用..Maxim,这不是对你问题的回答,而是一般性建议,通过评论的方式。你需要给批处理文件一个标题并按标题搜索,因为批处理文件是启动
cmd.exe
以执行批处理命令的序列文件。不要搜索volatile
cmd
title。查询
“从Win32_进程中选择名称、命令行、说明,其中名称='cmd.exe'
,然后选中
命令行