Reputation: 493
I want to auto-launch an application (specifically Outlook.exe) if it is not already running. I wanted to do this through the Windows 7 task scheduler, which meant the solution here did not work when I tried to execute it on one line by replacing the newline with &. It would launch outlook no matter if it was running or closed.
tasklist /FI "IMAGENAME eq outlook.exe" 2>NUL | find /I /N "outlook.exe">NUL & if "%ERRORLEVEL%"=="0" "C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"
Upvotes: 1
Views: 14418
Reputation: 49
Just to make a quick fix so the batch exits after successfully opening the file.
I added start ""
cmd.exe /c tasklist /FI "IMAGENAME eq outlook.exe" | find /I /N "outlook.exe" ||start "" "C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"
Upvotes: 4
Reputation: 493
I found this, which the second answer gave greater detail on the & and | options.
This is what ended up running well for me: cmd.exe /c tasklist /FI "IMAGENAME eq outlook.exe" | find /I /N "outlook.exe" || "C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"
More details: || [...] command1 || command2 Use to run the command following || only if the command preceding || fails. Cmd.exe runs the first command, and then runs the second command only if the first command did not complete successfully (receives an error code greater than zero).
Upvotes: 0