Steve Schofield's Blog

IIS7 - post #8

Here is sample code to return a collection of Application Pools using WMI and IIS7.  This is pretty dynamic because this could be used to retrieve from a local machine or altering the code to connect to a remote machine running IIS7.

'Define the WMI connection information
Dim options As New System.Management.ConnectionOptions()
'options.Username = strUID
'options.Password = strPWD

'Define the Scope information / Note the path defined.
Dim scope As System.Management.ManagementScope
scope =
New System.Management.ManagementScope(\\.\root\WebAdministration)

'Define Query and Searcher objects
Dim WMIQuery As New System.Management.SelectQuery("SELECT * FROM ApplicationPool")
Dim searcher As New System.Management.ManagementObjectSearcher(scope, WMIQuery)

'Connect to WMI
Try
       scope.Connect()
Catch ex As Exception
       Exit Sub
End Try

'Dim variables for information that will be returned
Dim AppPoolName As System.Management.ManagementObject
Dim col As System.Management.ManagementObjectCollection

'Return the collection
col = searcher.Get()

'Write the list of Application Pools to webpage
For Each AppPoolName In col
       Response.Write(AppPoolName.GetPropertyValue(
"Name").ToString() & "<BR>")
Next


Here is the IIS7'ish way of using the Microsoft.Web.Administration on a local machine.  I'm still trying to figure out how to use this new IIS7 namespace to connect to a remote machine.

        Dim Server As New Microsoft.Web.Administration.ServerManager  
        Dim col As ApplicationPoolCollection

        col = Server.ApplicationPools

        Dim AppPoolName As String = ""
        Dim x As Integer
       
        For x = 0 To col.Count - 1
            AppPoolName = col(x).Name
        Next
Share this post: Email it! | bookmark it! | digg it! | reddit!
Published Saturday, September 09, 2006 11:16 PM by Steve Schofield Weblog
Filed under: ,
Anonymous comments are disabled

Powered by Community Server 2.1