In addition to my porevious reply, Windows Server 2003 (and Windows XP) had the SC command.
sc query spooler
SERVICE_NAME: spooler
TYPE : 110 WIN32_OWN_PROCESS (interactive)
STATE : 4 RUNNING
(STOPPABLE,NOT_PAUSABLE,ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
sc stop Spooler
SERVICE_NAME: Spooler
TYPE : 110 WIN32_OWN_PROCESS (interactive)
STATE : 3 STOP_PENDING
(NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
sc query spooler
SERVICE_NAME: spooler
TYPE : 110 WIN32_OWN_PROCESS (interactive)
STATE : 1 STOPPED
(NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
You can 'sc stop spooler' or 'net stop spooler' and then:
for /f "Tokens=1-2* Delims=: " %%a in ('sc query spooler^|FIND "STATE"') do set STATE=%%b
if "%STATE%" EQU "1" goto stopped
On Thu, 17 Mar 2005 09:18:01 GMT, Antti H <(E-Mail Removed)> wrote:
>Hello,
>I am trying to improve our script that controls some services on our
>W2003 server.
>My goal is to determine in the batch file if the service actually goes
>down/up as supposed.
>
>
>See:
>
><
>E:\test>net stop spooler
>The Print Spooler service is stopping.
>The Print Spooler service was stopped successfully.
>
>
>E:\test>tasklist /SVC | find /C "Spooler"
>0
>
>E:\test>echo %ERRORLEVEL%
>0
> >
>
>
>errorlevel should be 1 instead of 0 ,no?
>
>If i could set the output of find to a variable, i would have no problem
>checking if %variable%==0 or similar. Is there any way to set variables
>with the output of a command inside batch, using only windows tools?
>
>Thank you all very much in advance,
>Antti H
>
>
>PS: Can anyone recommend a book that is useful as a command reference
> with examples for windows servers?
Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com