WorkerProcess.GetState 方法 2
返回工作进程的运行时状态。
语法
oWorkerProcess.GetState
var workerProcessState = objWorkerProcess.GetState();
参数
此方法不采用参数。
返回值
一个 uint32
,标识应用程序池状态。 下表显示了返回值。
返回值 | 说明 |
---|---|
0 | 指示工作进程正在启动。 |
1 | 指示工作进程正在运行。 |
2 | 指示工作进程正在停止。 |
3 | 指示工作进程未知。 |
注解
此方法对于 IIS 7 WMI 提供程序来说是新方法,在 IIS 6.0 中没有对应的方法。
示例
以下示例返回服务器上每个应用程序池中的每个工作进程的状态。
' 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
由于 WorkerProcess 是瞬态对象,因此在一段时间过后,当脚本运行时,WMI 报告的状态可能不再有效。
要求
类型 | 描述 |
---|---|
客户端 | - IIS 7.0(在 Windows Vista 上) - IIS 7.5(在 Windows 7 上) - IIS 8.0(在 Windows 8 上) - IIS 10.0(在 Windows 10 上) |
服务器 | - IIS 7.0(在 Windows Server 2008 上) - IIS 7.5(在 Windows Server 2008 R2 上) - IIS 8.0(在 Windows Server 2012 上) - IIS 8.5(在 Windows Server 2012 R2 上) - IIS 10.0(在 Windows Server 2016 上) |
产品 | - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0 |
MOF 文件 | WebAdministration.mof |
另请参阅
ApplicationPool 类
ApplicationPoolContainsProcess 类
WorkerProcess 类