IIS 6.0, Getting Information Using WMI - Can we retrieve IIS information using WMI? (Page 3 of 5 )
Why not? As WMI is also meant for system administration, obviously it boasts very good support for IIS. To find more information about WMI, you can refer to my previous articles at this website. To work with IIS and WMI together, we need to work with the classes existing in the “root\MicrosoftIISv2” namespace. This is a very important point to remember when working with WMI for IIS.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftIISv2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM IIsWebInfo",,48)
For Each objItem in colItems
Wscript.Echo objItem. MajorIIsVersionNumber & " -->: " & objItem. MinorIIsVersionNumber
Next
Within the above example, I am working with a class “IIsWebInfo” available in the “\\root\MicrosoftIISv2” namespace. “IIsWebInfo” mainly contains all information regarding version, status, install date, and so on.
Can we know, whether IIS is running or not using WMI? Certainly. Not only that, we can even retrieve further information about IIS (if it is still running) by using the following script:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftIISv2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM IIsWebService",,48)
For Each objItem in colItems
Wscript.Echo "DisplayName: " & objItem.DisplayName
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "PathName: " & objItem.PathName
Wscript.Echo "Started: " & objItem.Started
Wscript.Echo "State: " & objItem.State
Wscript.Echo "Status: " & objItem.Status
Wscript.Echo "SystemName: " & objItem.SystemName
Next
Within the above example, I am working with a class “IIsWebService” available in the “\\root\MicrosoftIISv2” namespace. “IIsWebService” gives more in-depth information than “IIsWebInfo”.
Next: Playing with Virtual directories and Web applications >>
More IIS Articles
More By Jagadish Chaterjee