Run an exe in a batch file, but check if its running first

Trying to write simple logic in a .bat file that checks if xxxx.exe is running on a workstation and, if not running, implement the xxxx.exe program.

The aforementioned xxxx.exe file is located in the following location:   C:\Program Files\xxxx.exe

Your help is greatly appreciated!

Abdel
Jabal_AwliyaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Peter HutchisonSenior Network Systems SpecialistCommented:
You need the PStools from Microsoft's Sysinternals website then run this:

PSList | Find "myprogram"
If Errorlevel 1 myprogram.exe


First line will get list of running processes and then search for the program name in the list.
If the previous command didn't find the program, then run it.
Jabal_AwliyaAuthor Commented:
I was looking for a script to enter into my .bat file. Is this possible
Jabal_AwliyaAuthor Commented:
?
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Peter HutchisonSenior Network Systems SpecialistCommented:
The two lines above can be included in your scripted batch file.
Jabal_AwliyaAuthor Commented:
Thanks for clarifying, sir.  That makes sense!  

Do I need to include the path as well or just the exe?

PSList | Find "COPITRAKDESKTOP10.exe"
If Errorlevel 1 C:\APPS\COPITRAK\COPITRAKDESKTOP10.exe
Peter HutchisonSenior Network Systems SpecialistCommented:
If the first line, it might not have the '.exe' part. Run PSList by itself to see what the actual name displays as, to ensure it will pick it up. The second line is ok.
Jabal_AwliyaAuthor Commented:
When running this script I get the following error:  "PSList is not recognized as an internal or external command, operable program or batch file"


What do I do?
Jabal_AwliyaAuthor Commented:
This is what I am testing out as a starter and its giving me the error:

@echo off

PSList | Find "COPITRAKDESKTOP10.exe"
If Errorlevel 1 ECHO Hello world
Peter HutchisonSenior Network Systems SpecialistCommented:
oBdACommented:
There's actually no need for external tools; just change the program path in line 3, the rest will automatically be taken care of:
@echo off
setlocal
set Program=C:\Program Files\xxxx.exe

for %%a in ("%Program%") do (
	set Folder=%%~dpa
	set Executable=%%~nxa
)
tasklist.exe /fi "IMAGENAME eq %Executable%" | find /i "%Executable%" >NUL
if errorlevel 1 (
	echo Starting '%Executable%' ...
	start "" /d "%Folder%" "%Program%"
) else (
	echo '%Executable%' already running.
)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jabal_AwliyaAuthor Commented:
Great. This seems so much easier, as downloading PSList is just not as straightforward as I had imagined...

I will test this out..

Thanks so much!
Jabal_AwliyaAuthor Commented:
This solution addresses my stated problem head-on.  Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.