DOS kicking my butt again

MaxBurn

Storage Is My Life
Joined
Jan 20, 2004
Messages
3,245
Location
SC
Ok so I have a total of four possible know services that could be running on a computer. Additionally I might have one that is stopped and set to manual with a newer one installed, if that is the case I can't touch that one. I only want to deal with the one that is running.

I am trying to make a bat file that will check for the running service, shut it down (do something) and then bring that ONE service back up.

I have been looking at these two sites:

http://www.geocities.com/rick_lively/MANUALS/COMMANDS/N/NETSTART.HTM
http://www.ss64.com/nt/sc.html

They both say I can use the commands there to check for a service name and use the errorlevel 0 or 1 to make a decision. My problem is that I seem to get errorlevel 1 NO MATTER WHAT I DO.

First one
Code:
SC QUERY "SSWeb 3.0 Service" |FINDSTR "STATE"
this one returns the string it found and an errorlevel 1 even though the FINDSTR error level 0 is what should be returned as it found a result????



Second one
Code:
NET START | FIND "SiteScan Web 3.0" > nul
doesn't matter what you try to find textwise, it is again always errorlevel 1


Third one same thing
Code:
SC query "SiteScan Web 2.0" | FIND "STATE"




I am using this to find error levels, found it with google. Handy for this.
Code:
@ECHO OFF
REM Reset variables
FOR %%A IN (1 10 100) DO SET ERR%%A=

REM Check error level hundredfolds
FOR %%A IN (0 1 2) DO IF ERRORLEVEL %%A00 SET ERR100=%%A
IF %ERR100%==2 GOTO 200
IF %ERR100%==0 IF NOT "%1"=="/0" SET ERR100=

REM Check error level tenfolds
FOR %%A IN (0 1 2 3 4 5 6 7 8 9) DO IF ERRORLEVEL %ERR100%%%A0 SET ERR10=%%A
IF "%ERR100%"=="" IF %ERR10%==0 SET ERR10=

:1
REM Check error level units
FOR %%A IN (0 1 2 3 4 5) DO IF ERRORLEVEL %ERR100%%ERR10%%%A SET ERR1=%%A
REM Modification necessary for errorlevels 250+
IF NOT ERRORLEVEL 250 FOR %%A IN (6 7 8 9) DO IF ERRORLEVEL %ERR100%%ERR10%%%A SET ERR1=%%A
GOTO End

:200
REM In case of error levels over 200 both
REM tenfolds and units are limited to 5
REM since the highest DOS error level is 255
FOR %%A IN (0 1 2 3 4 5) DO IF ERRORLEVEL 2%%A0 SET ERR10=%%A
IF ERR10==5 FOR %%A IN (0 1 2 3 4 5) DO IF ERRORLEVEL 25%%A SET ERR1=%%A
IF NOT ERR10==5 GOTO 1

:End
REM Clean up the mess and show results
SET ERRORLEV=%ERR100%%ERR10%%ERR1%
FOR %%A IN (1 10 100) DO SET ERR%%A=
ECHO ERRORLEVEL  %ERRORLEV%
 
Top