Sign in with
Sign up | Sign in
Your question

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

Last response: in Applications
Share
August 4, 2012 7:15:19 PM



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.

  1. @echo off
  2. net start | find "LoLLauncher" > nul 2>&1
  3. if not .%errorlevel%.==.0. goto startservice1
  4. goto autohotkey
  5.  
  6. :startservice1
  7. start "" "C:\Program Files (x86)\League of Legends\lol.launcher.exe"
  8.  
  9.  
  10. :autohotkey
  11. net start | find "AutoHotkey" > nul 2>&1
  12. if not .%errorlevel%.==.0. goto startservice2
  13. goto winamp
  14.  
  15. :startservice2
  16. start "" "C:\Program Files\AutoHotkey\AutoHotkey.exe"
  17.  
  18. :winamp
  19. net start | find "winamp" > nul 2>&1
  20. if not .%errorlevel%.==.0. goto startservice3
  21. goto skip
  22.  
  23. :startservice3
  24. start "" "C:\Program Files (x86)\Winamp\winamp.exe""
  25.  
  26. :skip
  27. exit

August 5, 2012 4:14:01 PM

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:

  1. @echo off
  2.  
  3. tasklist /FI "IMAGENAME eq AutoHotkey.exe" | find /i "AutoHotkey.exe"
  4.  
  5. IF ERRORLEVEL 2 GOTO NEXTPROGRAM
  6. IF ERRORLEVEL 1 GOTO LAUNCHPROGRAM
  7.  
  8. :NEXTPROGRAM
  9. goto LOLLAUNCHER
  10.  
  11.  
  12. :LAUNCHPROGRAM
  13. start "" "C:\Program Files\AutoHotkey\AutoHotkey.exe"
  14. goto LOLLAUNCHER
  15.  
  16. :LOLLAUNCHER
  17. tasklist /FI "IMAGENAME eq LoLLauncher.exe" | find /i "LoLLauncher.exe"
  18.  
  19. IF ERRORLEVEL 2 GOTO NEXTPROGRAM2
  20. IF ERRORLEVEL 1 GOTO LAUNCHPROGRAM2
  21.  
  22. :NEXTPROGRAM2
  23. goto COMPLETE
  24.  
  25.  
  26. :LAUNCHPROGRAM2
  27. start "" "C:\Program Files (x86)\League of Legends\lol.launcher.exe"
  28. goto COMPLETE

August 5, 2012 4:16:43 PM

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
February 6, 2013 8:18:23 AM

Or, much simpler (note that doing a goto to a goto isn't really that productive ;)  ):


@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"


Cheers,
Dominic Cioccarelli.
!