傳回背景工作進程的執行時間狀態。
語法
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 所報告的狀態在經過一段時間後可能不再有效。
規格需求
| 類型 | 描述 |
|---|---|
| Client | - Windows Vista 上的 IIS 7.0 - Windows 7 上的 IIS 7.5 - Windows 8 上的 IIS 8.0 - Windows 10上的 IIS 10.0 |
| 伺服器 | - Windows Server 2008 上的 IIS 7.0 - Windows Server 2008 R2 上的 IIS 7.5 - Windows Server 2012 上的 IIS 8.0 - Windows Server 2012 R2 上的 IIS 8.5 - Windows Server 2016上的 IIS 10.0 |
| 產品 | - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0 |
| MOF 檔案 | WebAdministration.mof |
另請參閱
ApplicationPool 類別
ApplicationPoolContainsProcess 類別
WorkerProcess 類別