# Batch File Help



## evangelistc01 (Apr 8, 2007)

I'm not ms-dos savvy, but I was wondering if I could have help throwing together a quick batch file (should be easy for you guys XD). Could a batch file achieve the following?

When I click on the shortcut to another application (lets say, a game), I need it to open another application at the same time. When I close the game, it needs to close the other application as well.


----------



## devil_himself (Apr 7, 2007)

You Can Start Both The Applications Using The Batch File



> When I close the game, it needs to close the other application as well


You Can User "Tasklist" To Determine If The Application is Running or Not .... If Not Running You Can "Taskkill" To Kill The Second Application .. If Still Running You Can ask The Script To Sleep For a particular Time and wait for the app to terminate

Try Something Like This

*To Make The Batch Wait*


```
setlocal
set seconds=%1
if "%seconds%"=="" set seconds=5
ping -n %seconds% localhost >nul
endlocal
```
*To Determine If App is Running Or Not*

Errlvl = 0 --> Running , Errlvl = 1 --> Not Running


```
Tasklist | Find /i "Notepad.exe"
IF "%ERRORLEVEL%" == "0" (
ECHO  Running
) Else (
Taskkill /f /im calc.exe
)
```


----------

