Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I came up with the batch file below, and it is working great. However, I would like to know if there is a way to code it so that if a program is already running, it would skip it and launch the next one. I hope this makes sense. Any advice would be greatly appreciated.

@echo off    
pushd    
start "" cmd /c cscript "C:\Users\User\Desktop\Work.vbs"    
start "C:\Program Files\Microsoft Office\Office15" Outlook.exe    
start "C:\Program Files\Microsoft Office\Office15" Lync.exe    
start "C:\Program Files (x86)\Google\Chrome\Application" chrome.exe    
runas /savecred /user:"DOMAIN\User_Adm" "C:\Program Files (x86)\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe"    
runas /savecred /user:"DOMAIN\User_Adm" "mmc.exe \"My_Tools.msc\"
share|improve this question

3 Answers 3

up vote 3 down vote accepted

Here is a example using tasklist to check all running applications for a given name.
Otherwise it starts the program. I'm sure you can adapt it to your needs

tasklist /nh /fi "imagename eq notepad.exe" | find /i "notepad.exe" > nul ||
(start notepad.exe)
share|improve this answer

I implemented tasklist into my script and its working like a charm.
Here it is for anyone else having the same questions as I had.

@echo off
pushd
tasklist /nh /fi "imagename eq iexplore.exe" | find /i "iexplore.exe" > nul ||(start Work.vbs)
tasklist /nh /fi "imagename eq outlook.exe" | find /i "outlook.exe" > nul ||(start outlook.exe)
tasklist /nh /fi "imagename eq lync.exe" | find /i "lync.exe" > nul ||(start lync.exe)
tasklist /nh /fi "imagename eq chrome.exe" | find /i "chrome.exe" > nul ||(start chrome.exe)
tasklist /nh /fi "imagename eq VpxClient.exe" | find /i "VpxClient.exe" > nul || runas /savecred /user:"DOMAIN\User_Adm" "C:\Program Files (x86)\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe"
tasklist /nh /fi "imagename eq mmc.exe" | find /i "mmc.exe" > nul || runas /savecred /user:"DOMAIN\User_Adm" "mmc.exe \"My_Tools.msc\"
share|improve this answer

@echo off

tasklist /FI "IMAGENAME eq outlook.exe" | find /i "outlook.exe"

IF ERRORLEVEL 2 GOTO LOOP2 IF ERRORLEVEL 1 GOTO LOOP1

:LOOP1 start notepad.exe goto EXIT

:LOOP1 start outlook.exe goto EXIT

:EXIT

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.