' ' check_iis_site.vbs - VB script to check the running/paused/stopped status ' of an IIS web site. Based on code from a script found ' on TechNet that gave information about IIS sites in ' general. ' 'Copyright (c) 2011 Chris Bensend (benny@bennyvision.com) ' All rights reserved. ' ' Redistribution and use in source and binary forms, with or without ' modification, are permitted provided that the following conditions ' are met: ' 1. Redistributions of source code must retain the above copyright ' notice, this list of conditions and the following disclaimer. ' 2. Redistributions in binary form must reproduce the above copyright ' notice, this list of conditions and the following disclaimer in the ' documentation and/or other materials provided with the distribution. ' ' THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ' ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ' IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ' ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE ' FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ' DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ' OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ' HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ' LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ' OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ' SUCH DAMAGE. ' ' v0.3 - 2011-01-25 - Now with "IIS is not installed" error-checking goodness, cjb ' v0.2 - 2010-08-16 - Slight output modification, cjb ' v0.1 - 2010-01-07 - Initial version, cjb Dim OutputCode, objParent, strSite, ComputerName, strOutput, SiteFound ' Default to an UNKNOWN error OutputCode = 3 ' Have we found this site yet? SiteFound = 0 args = WScript.Arguments.Count If args < 1 Then WScript.Echo "Usage: check_iis_site.vbs [IIS site comment]" WScript.Echo "" WScript.Echo "Note: The IIS site comment is the textual comment of the" WScript.Echo " site, NOT the virtual host name or IIS site number," WScript.Echo " and is case sensitive." WScript.Echo "" WScript.Quit( OutputCode ) End If IISsite = WScript.Arguments.Item(0) ComputerName = "Localhost" ' Attempt to enumerate the IIS sites. However, if IIS is not installed on this ' host, it will give us a runtime error with GetObject. Skip the error if we ' get it with 'On Error Resume Next', and then we can trap the problem below Err.Clear On Error Resume Next Set objParent = GetObject("IIS://" & ComputerName & "/W3SVC") If Err.Number <> 0 Then WScript.Echo "Error enumerating sites on " & ComputerName & " - Is IIS installed?" WScript.Quit( OutputCode ) End If ' Work our way through the list of sites and find the one we're looking at, if ' possible. I'm sure there is a better way to do this. For Each strSite in objParent If IsNumeric(strSite.Name) Then If strSite.ServerComment = IISsite Then SiteFound = 1 strOutput = "Web site: " & strSite.ServerComment ' ' IIS web site states, per MSDN: ' ' 1 = starting 5 = pausing ' 2 = started 6 = paused ' 3 = stopping 7 = continuing ' 4 = stopped ' Select Case strSite.ServerState Case 1 strOutput = strOutput & " : Starting" OutputCode = 1 Case 2 strOutput = strOutput & " : Started" OutputCode = 0 Case 3 strOutput = strOutput & " : Stopping" OutputCode = 1 Case 4 strOutput = strOutput & " : Stopped" OutputCode = 2 Case 5 strOutput = strOutput & " : Pausing" OutputCode = 1 Case 6 strOutput = strOutput & " : Paused" OutputCode = 2 Case 7 strOutput = strOutput & " : Continuing" OutputCode = 1 Case else strOutput = strOutput & " : UNKNOWN STATE " & strSite.ServerState End Select End If End If Next ' If we didn't find a site, error out If SiteFound <> 1 Then strOutput = "UNKNOWN: Site " & IISsite & " not found" OutputCode = 3 End If WScript.Echo strOutput WScript.Quit( OutputCode )