' Connect to the WMI WebAdministration namespace.
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
' Specify the application pool.
Set oAppPool = oWebAdmin.Get("ApplicationPool.Name='DefaultAppPool'")
' Get the application pool's state and return it to the user by
' calling a helper function.
WScript.Echo oAppPool.Name & " is " & GetStateDescription(oAppPool.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
Source