Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bat file help? 1

Status
Not open for further replies.

pinkpanther56

Technical User
Jun 15, 2005
807
GB
I can't really find a forum for bat file help so I thought a windows forum might have an answer.

I'd like to have a batch file that runs as a logon script that will check to see if a program (or 2) is already running before launching them.

Can anyone assist?

This will be on an XP Home laptop so group policy isn't an option.

Thanks.
 
You won't be able to do this easily with the tools built into XP. However, if you add the SysInternals Suite, you can probably use PSList in a batch file to do what you want.
 
Or you can try

Code:
tasklist /FI "IMAGENAME eq <your process>"

But that doesn't hide you have a problem at logon script if you have to check for a program

Cheers,
Dian
 
Thanks for the reply.

The problem I have is that when the bat file tries to launch the exe if the exe is running it pauses, is there a way to make it attempt to run the exe and after a couple of seconds skip on rather than waiting?

Thanks.
 
Thanks for the reply Dian.

The tasklist idea shows promise how would I make a batch command check this and skip if it exists?

Thanks.
 
If it's a logon script, how comes the program can be already running?

Anyway, you can have plenty of examples here

Cheers,
Dian
 
I'm trying to work around an issue with some software, the same script is run at logon and logoff. It runs fine at logon but during logoff the process already exists so I need to it to skip that line when the script is run during logoff.

Thanks for the examples i'll take a look.
 
Sorted thanks for the help.

Code:
tasklist /FI "IMAGENAME eq tray.exe" /FO CSV > search.log 
 
FOR /F %%A IN (search.log) DO IF %%~zA EQU 0 GOTO end 
 
"C:\Program Files\Citrix\ICA Client\pn.exe" /APP "Desktop"

start "" "C:\Program Files\Hotkey Utility\tray.exe"

:end 
 
del search.log
 
If you look in the link I provided, there's an easier solution that doesn't need an intermediate results file

Cheers,
Dian
 
I did see that but I couldn't get it to work for some reason, maybe i'll take another look now I know I have a working solution.
 
Just thought that i'd post the final working file.

Code:
tasklist /FI "IMAGENAME eq tray.exe" 2>NUL | find /I /N "tray.exe">NUL 
if "%ERRORLEVEL%"=="1" start "" "C:\Program Files\Hotkey Utility\tray.exe"

EXIT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top