# Create a multi- IF/ELSE batch file?



## sbw07 (Jul 29, 2008)

Hi,
I would appreciate some help on writing a batch file.

What I want to do is to turn 2 apps on/off depending on which, or any, of them was active before execution of the batch file.
i.e. if both apps are off turn them on, and vice versa, if only #1 is active kill it, & if only # 2 is active turn on # 1

So far I was only able to do a simple IF/ELSE that will either turn them both on or off. It looks like

@echo off
tasklist | FIND /I "TjLec.exe"
IF ERRORLEVEL 1 (
START "TJ" "C:\Program Files\TJNet Lec\TjLec.exe"
START "MJ" "C:\Program Files\Magicjack\magicJack.exe" 
) ELSE (
taskkill /IM magicjack.exe
taskkill /IM TjLec.exe
)


----------



## devil_himself (Apr 7, 2007)

wrote this in a hurry before leaving town

```
@echo off
setlocal
 
:: Define operating environment
set app1=notepad.exe
set app2=calc.exe
 
::Verify Instance Running
tasklist |find /i "%app1%" >nul
if "%errorlevel%"=="1" set a1=N
if "%errorlevel%"=="0" set a1=Y

tasklist |find /i "%app2%" >nul
if "%errorlevel%"=="1" set a2=N
if "%errorlevel%"=="0" set a2=Y

if "%a1%"=="N" if "%a2%"=="N" (
	start "" "%app1%"
	start "" "%app2%"
)

if "%a1%"=="Y" if "%a2%"=="Y" (
	taskkill /f /im "%app1%"
	taskkill /f /im "%app2%"
)


::if only #1 is active kill it
if "%a1%"=="Y" if "%a2%"=="N" taskkill /f /im "%app1%" >nul

::if #2 is active turn #1 on
if "%a1%"=="N" if "%a2%"=="Y" start "" "%app1%"
```


----------

