17 August 2007

Check Service Status

Most Windows 2000 / 2003 servers running IIS, have remote registry access disabled, for security reasons. by using psservice I've write a script to determine if the IISADMIN and W3SVC service is running on remote Server:

@Echo off
rem This Script Check the Status of IISADMIN & W3SVC (IIS Server)

SET STATE=
SET SERVICE1=IISADMIN
SET SERVER1=172.1.2.12

:IISADMIN
For /F "Tokens=3 Delims=: " %%a in ('psservice \\%SERVER1% query %SERVICE1%^|find /i "STATE"') do SET STATE=%%a
if "%STATE%" EQU "RUNNING" goto W3SVC

:W3SVC
For /F "Tokens=3 Delims=: " %%a in ('psservice \\%SERVER1% query %SERVICE1%^|find /i "STATE"') do SET STATE=%%a
if "%STATE%" EQU "RUNNING" goto END

:Status
@echo The %SERVICE1% on %SERVER1% is %STATE%
goto END

:END

Note: In my case, the Server's IP is: 172.1.2.12
You can change the line "@echo The %SERVICE1% on %SERVER1% is %STATE%" in Status block to any command, for example to command that send e-mail to you about status of the Server.


Bookmark and Share ITStuff.ca

No comments:

Post a Comment