I need some help I can't get this to work. I am trying to write a batch that will check for a specific process. If the process is running it will check it again and if the process is off it will start it. Here is what i have so far but i keep getting a generic error.
@echo off
:THERE
Start chrome.exe
:HERE
tasklist /fi "STATUS eq chrome.exe" >nul
If errorlevel 1 goto THERE else goto HERE
pause
Help please
Moderator: DosItHelp
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
I was under the impression that if ELSE was used with IF then it needed to be formatted with parrenthesis...
IF ERRORLEVEL 1 (DO ONE) ELSE (DO TWO)
IF ERROR LEVEL 1 (
DO ONE
)
ELSE
(
DO TWO
)
Also, I've had issues using GOTO statements within if statements. I've often done something like ECHO. & GOTO HERE in order to get it to work correctly because it wouldn't work with just a GOTO HERE.
IF ERRORLEVEL 1 (DO ONE) ELSE (DO TWO)
IF ERROR LEVEL 1 (
DO ONE
)
ELSE
(
DO TWO
)
Also, I've had issues using GOTO statements within if statements. I've often done something like ECHO. & GOTO HERE in order to get it to work correctly because it wouldn't work with just a GOTO HERE.
-
- Posts: 23
- Joined: 02 Jan 2010 20:54
The Great One
I have a Russian M$ "Windows", so I do not know, really need to look for "Running" or another word. Check it before use, otherwise you bury surf windows
Or, if you do not need to check the Hanging application, then simply write:
I have a Russian M$ "Windows", so I do not know, really need to look for "Running" or another word. Check it before use, otherwise you bury surf windows
Code: Select all
@echo off
:nono
tasklist /v /fi "imagename eq calc.exe" 2>nul |findstr "Running" >nul ||start calc.exe
goto :nono
Or, if you do not need to check the Hanging application, then simply write:
Code: Select all
@echo off
:load
tasklist |findstr "calc.exe" >nul ||start calc.exe
goto :load
-
- Posts: 23
- Joined: 02 Jan 2010 20:54