Retrieving IIS information using ASP.NET 2.0 - Can we learn more about the virtual directories (including web application information) present in IIS using ASP.NET 2.0? (Page 4 of 4 )
We can dig still further, but with a different class, as shown in the following program.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim dt As DataTable = getStruct()
Dim dr As DataRow
Dim searcher As New ManagementObjectSearcher("root\MicrosoftIISv2", "SELECT * FROM IIsWebVirtualDirSetting")
For Each queryObj As ManagementObject In searcher.Get()
dr = dt.NewRow
dr("AppPoolId") = queryObj("AppPoolId")
dr("Name") = queryObj("Name")
dr("Path") = queryObj("Path")
dr("EnableDirBrowsing") = queryObj("EnableDirBrowsing")
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 further in-depth information about the virtual directories, we need to work with the class “IIsWebVirtualDirSettng.” It also has a lot of properties. I 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 getStruct() As DataTable
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("Name"))
dt.Columns.Add(New DataColumn("Path"))
dt.Columns.Add(New DataColumn("AppPoolId"))
dt.Columns.Add(New DataColumn("EnableDirBrowsing"))
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.
How about retrieving SMTP, FTP, POP3 information using ASP.NET 2.0?
We can even retrieve that information as well. But we need to switch back again to the first style. Let us proceed with the following code.
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 IIsSmtpService")
For Each queryObj As ManagementObject In searcher.Get()
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") = "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
To retrieve information about SMTP, we need to work with the class “IIsSmtpService.” Similarly, to work with FTP, we need to work with “IIsFtpService,” and so on.
Any comments, suggestions, ideas, improvements, bugs, errors, feedback etc. are highly appreciated at jag_chat@yahoo.com.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |