Navigation:  System Health Monitoring > Monitor IIS Web Sites >

iis_list_stopped_w3svc_sites.vbs

Top  Previous  Next

' Supported Platforms: Windows 2003 and earlier

'

' Lists the state of all IIS web sites configured on the local machine

' and returns an %ERRORLEVEL% of 1, if at least one web site is not in

' the "Started" state.

'

' When scheduling this script with EventSentry's application scheduler,

' make sure that the interpreter is set to "cscript.exe"

 

Option Explicit

 

Dim strServer, strServerType, strServerMetaType

Dim objService

Dim returnCode

 

returnCode                        = 0

strServer                        = "localhost"

strServerType                = "Web"

strServerMetaType        = "W3SVC"

 

Sub EnumServersites( objService )

 Dim objServer

 

   For Each objServer In objService

       If objServer.Class = "IIs" & strServerType & "Server" Then

                     If SiteIsNotRunning(objServer.ServerState) Then

                             WScript.StdOut.Write "*"

                     End If

                     

           WScript.StdOut.Write _

               objServer.ServerComment & ": " & State2Desc( objServer.ServerState )

               

                     If SiteIsNotRunning(objServer.ServerState) Then

                             WScript.StdOut.Write "*"

                             returnCode = 1

                     End If

                     

                     WScript.StdOut.Write vbCRLF

       End If

   Next

End Sub

 

Function SiteIsNotRunning( nState )

 

 If nState <> 2 Then

         SiteIsNotRunning = 1

 Else

         SiteIsNotRunning = 0

 End If

 

End Function

 

Function State2Desc( nState )

 

   Select Case nState

   Case 1

         'MD_SERVER_STATE_STARTING

       State2Desc = "Starting"

   Case 2

         'MD_SERVER_STATE_STARTED

       State2Desc = "Started"

   Case 3

         'MD_SERVER_STATE_STOPPING

       State2Desc = "Stopping"

   Case 4

         'MD_SERVER_STATE_STOPPED

       State2Desc = "Stopped"

   Case 5

         'MD_SERVER_STATE_PAUSING

       State2Desc = "Pausing"

   Case 6

         'MD_SERVER_STATE_PAUSED

       State2Desc = "Paused"

   Case 7

         'MD_SERVER_STATE_CONTINUING

       State2Desc = "Continuing"

   Case Else

       State2Desc = "Unknown state"

   End Select

 

End Function

 

SET objService = GetObject( "IIS://" & strServer & "/" & strServerMetaType )

EnumServersites objService

 

If returnCode <> 0 Then

 WScript.Echo vbCRLF & "WARNING: One or more IIS sites are not running" & vbCRLF

End If

 

WScript.Quit returnCode