Retrieving IIS information using ASP.NET 2.0 - Retrieving basic IIS information using ASP.NET 2.0 (Page 2 of 4 )
The following program helps you to retrieve basic IIS information.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim dt As DataTable = getPropertyStruct()
Dim dr As DataRow
Dim searcher As New ManagementObjectSearcher("root\MicrosoftIISv2", "SELECT * FROM IIsWebInfo")
For Each queryObj As ManagementObject In searcher.Get()
dr = dt.NewRow
dr("Name") = "Caption"
dr("value") = queryObj("Caption")
dt.Rows.Add(dr)
dr = dt.NewRow
dr("Name") = "Description"
dr("value") = queryObj("Description")
dt.Rows.Add(dr)
dr = dt.NewRow
dr("Name") = "InstallDate"
dr("value") = queryObj("InstallDate")
dt.Rows.Add(dr)
dr = dt.NewRow
dr("Name") = "MajorIIsVersionNumber"
dr("value") = queryObj("MajorIIsVersionNumber")
dt.Rows.Add(dr)
dr = dt.NewRow
dr("Name") = "MinorIIsVersionNumber"
dr("value") = queryObj("MinorIIsVersionNumber")
dt.Rows.Add(dr)
dr = dt.NewRow
dr("Name") = "Name"
dr("value") = queryObj("Name")
dt.Rows.Add(dr)
dr = dt.NewRow
dr("Name") = "Status"
dr("value") = queryObj("Status")
dt.Rows.Add(dr)
Next
Me.GridView1.DataSource = dt
Me.GridView1.DataBind()
Catch err As ManagementException
Response.Write(err.Message)
End Try
End Sub
Details about the program
Even though the above program is a bit lengthy, it is very simple to understand. In the above program I am using “getPropertyStruct,” which is used to create and return a data table which can hold any number of “key,value” pairs. You can also work with “collections” instead of working with the “data table.” “getPropertyStruct” is defined as follows:
Private Function getPropertyStruct() As DataTable
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("Name"))
dt.Columns.Add(New DataColumn("Value"))
Return dt
End Function
The main statements within the above program (in the previous section) are as follows:
Dim searcher As New ManagementObjectSearcher("root\MicrosoftIISv2", "SELECT * FROM IIsWebInfo")
For Each queryObj As ManagementObject In searcher.Get()
The first statement connects to the “root\MicrosoftIISv2” namespace. We are trying to issue a SELECT statement based on a built-in class, “IIsWebInfo.” It would return all the objects associated with the class “IIsWebInfo” and I handle them (each) with “queryObj” which is of type “ManagementObject.”
With every object I receive from “queryObj,” I extract the information into a new “data row” which would finally be added to the “data table” (as follows).
dr = dt.NewRow
dr("Name") = "Name"
dr("value") = queryObj("Name")
dt.Rows.Add(dr)
Finally, I assign the data table information to the grid by issuing the following statements:
Me.GridView1.DataSource = dt
Me.GridView1.DataBind()
The next section further digs out the IIS information.
Next: Digging further for IIS information using ASP.NET 2.0 >>
More IIS Articles
More By Jagadish Chaterjee