Search code examples
windowsvbscriptcmdtasklist

tasklist show all windows


I am running the following batch script:

@echo off
tasklist /nh /fi "Windowtitle eq Export to PDF - DOORS" | find /i "Export to PDF - DOORS" >nul && (
echo PDF is running
) || (
echo PDF is not running
)

This only echos "PDF is running" if the window is currently active. Perhaps I am using the wrong command (tasklist). Is there a way to find in the full list of open windows?


Solution

  • I was able to get what I needed with a VB Script (Thanks @JoshGuzman for the idea):

    Set Word = CreateObject("Word.Application")
    Set Tasks = Word.Tasks
    
    For Each Task in Tasks
      If Task.Visible Then
        If Task.name = "Export to PDF - DOORS" Then
          Wscript.Echo "PDF is Running"
        Else 
          Wscript.Echo "PDF is not Running"
        End If
      End If
    Next
    
    Word.Quit
    

    Then call the VB script with wscript myScript.vbs from the command prompt or a batch file.