Page 1 of 1

Test if a Windows-based Application is Running

Posted: 14 Aug 2008 10:26
by jonno
Hello,

I've spent a few hours googling and have come up empty.

I need to create a DOS script (I call them batch files) where I test if a windows based application is running. If so, I want to set focus to the application (similar to the API function 'ShowWindow' or 'SetForegroundWindow'). and if the app is not running - simply run it.

Thanks for any direction on this.

Jon

Re: Test if a Windows-based Application is Running

Posted: 04 Sep 2008 06:21
by Skeletor
jonno wrote:Hello,

I've spent a few hours googling and have come up empty.

I need to create a DOS script (I call them batch files) where I test if a windows based application is running.


@echo off
IF "%1" == "" (Echo Syntax... istask {task}&pause&GOTO :eof)
set task=%1
set task=%task:"=%
tasklist /FI "IMAGENAME eq %task%" | find /i "%task%" >NUL:
goto task%ERRORLEVEL%
:task0
Echo INFO: Found task %task%
goto :eof
:task1 Start it
"%task%"
goto :eof