Site.GetState Method1

Returns the run-time state of a Web site.

Syntax

objSite.GetState  
var siteState = objSite.GetState();  

Parameters

This method takes no parameters.

Return Value

A uint32 that identifies the Web site state. The return values are shown in the following table.

Return value Description
0 Indicates that the Web site is starting.
1 Indicates that the Web site has started.
2 Indicates that the Web site is stopping.
3 Indicates that the Web site has stopped.
4 Indicates that the Web site state is unknown.

Example

The following example gets the state of a Web site and returns it to the user.

' Connect to the WMI WebAdministration namespace.  
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")  
  
' Specify the Web site.  
Set oSite = oWebAdmin.Get("Site.Name='IISWebSite'")  
  
' Get the Web site's state and return it to the user by  
' calling a helper function.  
WScript.Echo oSite.Name & " is " & GetStateDescription(oSite.GetState) & "."  
  
' The helper function translates the return value into text.  
Function GetStateDescription(StateCode)  
    Select Case StateCode  
        Case 0  
            GetStateDescription = "Starting"  
        Case 1  
            GetStateDescription = "Started"  
        Case 2  
            GetStateDescription = "Stopping"  
        Case 3  
            GetStateDescription = "Stopped"  
        Case 4  
            GetStateDescription = "Unknown"  
        Case Else  
            GetStateDescription = "Attempt to retrieve state failed."  
    End Select  
End Function  

Requirements

Type Description
Client - IIS 7.0 on Windows Vista
- IIS 7.5 on Windows 7
- IIS 8.0 on Windows 8
- IIS 10.0 on Windows 10
Server - IIS 7.0 on Windows Server 2008
- IIS 7.5 on Windows Server 2008 R2
- IIS 8.0 on Windows Server 2012
- IIS 8.5 on Windows Server 2012 R2
- IIS 10.0 on Windows Server 2016
Product - IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0
MOF file WebAdministration.mof

See Also

Site Class