tasklist show all windows

Steve Valliere picture Steve Valliere · Aug 29, 2012 · Viewed 8.7k times · Source

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?

Answer

Steve Valliere picture Steve Valliere · Sep 4, 2012

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.