PC Review


Reply
Thread Tools Rate Thread

Checking service status?

 
 
Antti H
Guest
Posts: n/a
 
      17th Mar 2005
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?
 
Reply With Quote
 
 
 
 
Jerold Schulman
Guest
Posts: n/a
 
      17th Mar 2005

@echo off
setlocal
set OK=N
for /f "Tokens=*" %%a in ('net stop spooler^|find /i "stopped successfully"') do (
set OK=Y
)
If "%OK%" EQU "N" (
@echo The Spooler server did not stop successfully.
) ELSE (
@echo The Spooler server stopped successfully.
)
endlocal

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
 
Reply With Quote
 
Jerold Schulman
Guest
Posts: n/a
 
      17th Mar 2005

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
 
Reply With Quote
 
Al Dunbar [MS-MVP]
Guest
Posts: n/a
 
      18th Mar 2005

"Jerold Schulman" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> @echo off
> setlocal
> set OK=N
> for /f "Tokens=*" %%a in ('net stop spooler^|find /i "stopped

successfully"') do (
> set OK=Y
> )
> If "%OK%" EQU "N" (
> @echo The Spooler server did not stop successfully.
> ) ELSE (
> @echo The Spooler server stopped successfully.
> )
> endlocal


Any reason why this wouldn't work:

net stop spooler | find /i "stopped successfully"
if errorlevel 1 (
echo The Spooler server did not stop successfully.
) ELSE (
echo The Spooler server stopped successfully.
)

/Al

> 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



 
Reply With Quote
 
Jerold Schulman
Guest
Posts: n/a
 
      18th Mar 2005

I tend not to rely on ERRORLEVEL as I found that it is too often 'broken' between various O/S versions and hotfixes and Service Packs.

On Thu, 17 Mar 2005 22:14:24 -0700, "Al Dunbar [MS-MVP]" <alan-no-drub-(E-Mail Removed)> wrote:

>
>"Jerold Schulman" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>>
>> @echo off
>> setlocal
>> set OK=N
>> for /f "Tokens=*" %%a in ('net stop spooler^|find /i "stopped

>successfully"') do (
>> set OK=Y
>> )
>> If "%OK%" EQU "N" (
>> @echo The Spooler server did not stop successfully.
>> ) ELSE (
>> @echo The Spooler server stopped successfully.
>> )
>> endlocal

>
>Any reason why this wouldn't work:
>
> net stop spooler | find /i "stopped successfully"
> if errorlevel 1 (
> echo The Spooler server did not stop successfully.
> ) ELSE (
> echo The Spooler server stopped successfully.
> )
>
>/Al
>
>> 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

>



Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
checking microphone status =?Utf-8?B?R3JlZw==?= Microsoft Dot NET 0 4th May 2006 06:30 PM
checking the status of my service =?Utf-8?B?U0tCZXJnYW0=?= Microsoft Dot NET 0 16th Nov 2004 05:08 PM
Checking Site Status ? T :-\) Microsoft VB .NET 2 22nd Oct 2004 04:11 PM
Checking status of sent message Rhonda Microsoft Outlook Discussion 2 27th Aug 2004 08:54 PM
checking CPU and memory status Ofer B. Microsoft Dot NET Compact Framework 3 24th May 2004 01:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:55 AM.