WorkerProcess.GetState Method2
Returns the run-time state of a worker process.
oWorkerProcess.GetState
var workerProcessState = objWorkerProcess.GetState();
This method takes no parameters.
A uint32
that identifies the application pool state. The return values are shown in the following table.
Return value | Description |
---|---|
0 | Indicates that the worker process is starting. |
1 | Indicates that the worker process is running. |
2 | Indicates that the worker process is stopping. |
3 | Indicates that the worker process is unknown. |
This method is new to the IIS 7 WMI provider and has no counterpart in IIS 6.0.
The following example returns the state of every worker process in each application pool on a server.
' Connect to the WMI WebAdministration namespace.
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
' Return all application pools that are present on the server.
Set colAppPools = oWebAdmin.ExecQuery("SELECT * FROM ApplicationPool")
' Return each application pool name.
For Each oAppPool In colAppPools
WScript.Echo oAppPool.Name
WScript.Echo String(Len(oAppPool.Name), "-")
' Get all worker processes in the application pool.
Set oWorkerProcesses = _
oAppPool.Associators_("ApplicationPoolContainsProcess")
' Return each worker process ID and report its state by using
' the GetStateDescription helper function.
For Each oWorkerProcess In oWorkerProcesses
WScript.Echo "Process ID " & oWorkerProcess.ID & _
" is " & GetStateDescription(oWorkerProcess.GetState) & "."
Next
WScript.Echo
Next
' Return the text string that corresponds to the state code.
Function GetStateDescription(StateCode)
Select Case StateCode
Case 0
GetStateDescription = "starting"
Case 1
GetStateDescription = "running"
Case 2
GetStateDescription = "stopping"
Case 3
GetStateDescription = "unknown"
Case Else
GetStateDescription = _
"Attempt to retrieve worker process state failed."
End Select
End Function
Because WorkerProcess is a transient object, the state reported by WMI when the script is run may no longer be valid after some time has elapsed.
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 |
ApplicationPool Class
ApplicationPoolContainsProcess Class
WorkerProcess Class