Retrieving IIS information using ASP.NET 2.0 - Digging further for IIS information using ASP.NET 2.0 (Page 3 of 4 )
The modified code, to have a bit more information, would be as follows:
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 IIsWebService")
For Each queryObj As ManagementObject In searcher.Get()
dr = dt.NewRow
dr("Name") = "Name"
dr("value") = queryObj("Name")
dt.Rows.Add(dr)
dr = dt.NewRow
dr("Name") = "DisplayName"
dr("value") = queryObj("DisplayName")
dt.Rows.Add(dr)
dr = dt.NewRow
dr("Name") = "PathName"
dr("value") = queryObj("PathName")
dt.Rows.Add(dr)
dr = dt.NewRow
dr("Name") = "Started"
dr("value") = queryObj("Started")
dt.Rows.Add(dr)
dr = dt.NewRow
dr("Name") = "State"
dr("value") = queryObj("State")
dt.Rows.Add(dr)
dr = dt.NewRow
dr("Name") = "Status"
dr("value") = queryObj("Status")
dt.Rows.Add(dr)
dr = dt.NewRow
dr("Name") = "SystemName"
dr("value") = queryObj("SystemName")
dt.Rows.Add(dr)
Next
Me.GridView1.DataSource = dt
Me.GridView1.DataBind()
Catch err As ManagementException
Response.Write(err.Message)
End Try
End Sub
This time, instead of working with the “IIsWebInfo” class, I shifted to another class, “IIsWebService,” which gives you much more information than the previous class.
Retrieving all virtual directories present in IIS using ASP.NET 2.0
This is a bit different from the above coding style. First of all, let us look at the program.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim dt As DataTable = getVirtualRootStruct()
Dim dr As DataRow
Dim searcher As New ManagementObjectSearcher("root\MicrosoftIISv2", "SELECT * FROM IIsWebVirtualDir")
For Each queryObj As ManagementObject In searcher.Get()
dr = dt.NewRow
dr("AppRoot") = queryObj("AppRoot")
dr("Caption") = queryObj("Caption")
dr("Description") = queryObj("Description")
dr("Name") = queryObj("Name")
dr("Status") = 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
To get the virtual directory information, we need to work with the class “IIsWebVirtualDir”. It has got a lot of properties. I just selected only the most important ones. I am using another routine to form a structure, to store that property information. The routine is as follows.
Private Function getVirtualRootStruct() As DataTable
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("AppRoot"))
dt.Columns.Add(New DataColumn("Caption"))
dt.Columns.Add(New DataColumn("Description"))
dt.Columns.Add(New DataColumn("Name"))
dt.Columns.Add(New DataColumn("Status"))
Return dt
End Function
All the columns are indirectly nothing but the properties, and the rest is the same as I explained in the first section.
Next: Can we learn more about the virtual directories (including web application information) present in IIS using ASP.NET 2.0? >>
More IIS Articles
More By Jagadish Chaterjee