Start program if not running (but with multiple programs in .bat)

Status
Not open for further replies.

Jdust

Honorable
Aug 4, 2012
4
0
10,510
Let me be honest, i'm not that good at programming. But i what I like about it is to make things easier. And i'm trying to make a .bat file to open both League of Legends, Autohotkey (for changing songs ingame) and winamp at the same time, but the tricky part is too make sure they don't do anything if it's already running. I investigated it a bit on this site, but didn't find something specific for my needs. But i tried to make a .bat file, with the information i gathered, ran it, but it opens the programs although they're already running. Since i'm new to this, i'm guessing one of the problems is the several different startservices (or maybe you can't name it like :autohotkey), the program name (fx find "LoLLauncher", in process lists it's called LoLLauncher.exe *32) and maybe other problems. This would make my gaming easier if you would tell me if i'm right about my troubleshooting.

I would really appreciate it if you would have a look at it :)

Update: Forgot to write my system info:
Windows 7 Ultimate 64 bit

Another update: What i really want is just a shortcut that can do this, if you have a better/easier suggestion please share.

Code:
@echo off 
net start | find "LoLLauncher" > nul 2>&1 
if not .%errorlevel%.==.0. goto startservice1
goto autohotkey

:startservice1
start "" "C:\Program Files (x86)\League of Legends\lol.launcher.exe"


:autohotkey
net start | find "AutoHotkey" > nul 2>&1 
if not .%errorlevel%.==.0. goto startservice2
goto winamp

:startservice2
start "" "C:\Program Files\AutoHotkey\AutoHotkey.exe"

:winamp
net start | find "winamp" > nul 2>&1 
if not .%errorlevel%.==.0. goto startservice3
goto skip 

:startservice3
start "" "C:\Program Files (x86)\Winamp\winamp.exe"" 

:skip 
exit
 

Jdust

Honorable
Aug 4, 2012
4
0
10,510
Been searching around while waiting for replys, and finally found a solution. Feel free to use this aswell. Quick Info: Found out that i can edit autohotkey script to open winamp if not open, so i only have to launch that one along with league of legends. Here is the complete script. If you want to use it, replace the LoLLauncher and Autohotkey with your programs and paths:

Code:
@echo off 
 
tasklist /FI "IMAGENAME eq AutoHotkey.exe" | find /i "AutoHotkey.exe" 
 
IF ERRORLEVEL 2 GOTO NEXTPROGRAM
IF ERRORLEVEL 1 GOTO LAUNCHPROGRAM
 
:NEXTPROGRAM
goto LOLLAUNCHER

 
:LAUNCHPROGRAM
start "" "C:\Program Files\AutoHotkey\AutoHotkey.exe"
goto LOLLAUNCHER
 
:LOLLAUNCHER
tasklist /FI "IMAGENAME eq LoLLauncher.exe" | find /i "LoLLauncher.exe" 

IF ERRORLEVEL 2 GOTO NEXTPROGRAM2
IF ERRORLEVEL 1 GOTO LAUNCHPROGRAM2

:NEXTPROGRAM2
goto COMPLETE

 
:LAUNCHPROGRAM2
start "" "C:\Program Files (x86)\League of Legends\lol.launcher.exe"
goto COMPLETE
 

Jdust

Honorable
Aug 4, 2012
4
0
10,510
One you can copy without the line numbers:

@echo off

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

IF ERRORLEVEL 2 GOTO NEXTPROGRAM
IF ERRORLEVEL 1 GOTO LAUNCHPROGRAM

:NEXTPROGRAM
goto LOLLAUNCHER


:LAUNCHPROGRAM
start "" "C:\Program Files\AutoHotkey\AutoHotkey.exe"
goto LOLLAUNCHER

:LOLLAUNCHER
tasklist /FI "IMAGENAME eq LoLLauncher.exe" | find /i "LoLLauncher.exe"

IF ERRORLEVEL 2 GOTO NEXTPROGRAM2
IF ERRORLEVEL 1 GOTO LAUNCHPROGRAM2

:NEXTPROGRAM2
goto COMPLETE


:LAUNCHPROGRAM2
start "" "C:\Program Files (x86)\League of Legends\lol.launcher.exe"
goto COMPLETE
 

dcioccarelli

Honorable
Feb 6, 2013
1
0
10,510
Or, much simpler (note that doing a goto to a goto isn't really that productive ;) ):

[fixed]
@echo off

tasklist /FI "IMAGENAME eq AutoHotkey.exe" | find /i "AutoHotkey.exe"
IF ERRORLEVEL 1 start "" "C:\Program Files\AutoHotkey\AutoHotkey.exe"
tasklist /FI "IMAGENAME eq LoLLauncher.exe" | find /i "LoLLauncher.exe"
IF ERRORLEVEL 1 start "" "C:\Program Files (x86)\League of Legends\lollauncher.exe"
[/fixed]

Cheers,
Dominic Cioccarelli.
 
Status
Not open for further replies.