Computer Hope

Microsoft => Microsoft Windows => Windows XP => Topic started by: n2tech on July 14, 2007, 08:46:58 PM

Title: Batch File to check for a program running in memory
Post by: n2tech on July 14, 2007, 08:46:58 PM
I need to have a way to check and see if a program is running then open it if it is not running.  This is basically what I need:

If Program is running
     Goto End
Else Start Program
End

Can anyone help with this?

Thanks,
Mark Sharp
N2Tech
E-Mail address edited out to prevent spam...
Title: Re: Batch File to check for a program running in memory
Post by: Dark Blade on July 15, 2007, 12:45:15 AM
Code: [Select]
@echo off
tasklist | find "iexplore.exe" && goto end
start iexplore.exe
:end
Title: Re: Batch File to check for a program running in memory
Post by: contrex on July 15, 2007, 01:34:35 AM
Or you can use handle.exe from the Microsoft Sysinternals collection of utilities.

And you can use the start "" "program.exe" format to make the batch continue & maybe exit.

http://www.microsoft.com/technet/sysinternals/Processesandthreadsutilities.mspx?wt.svl=featured

And just to be contrary, I show the use of || thus avoiding the use of a label. In fact by choosing && or || appropriately you never need use labels.

Quote
handle | find /i "extradns.dll" > nul || (
        echo ExtraDNS not detected - starting now!
        start "" "C:\Program Files\ExtraTools\ExtraDNS\ExtraDNS.exe"
        )