Listing/Modifying Server Information with Visual Basic.NET and VBScript Using WMI (Page 1 of 5 )
This article explains how you can retrieve Windows server information using both Visual Basic.NET and VBScript, along with WMI.
A downloadable file for this article is available
here.
The sample downloadable solution (zip) is entirely developed using Visual Studio.NET 2003 Enterprise Architect on Windows Server 2003 Standard Edition. But, I am confident that it would work with other versions of Windows (which support .NET 1.1) versions as well.
Some global routines used for my WMI development
Let me first address some issues. I received a lot of feedback from several readers throughout the world on my series “WMI Programming with Visual Basic.NET”. Almost every one (about 80%) requested that I extend the series with much more useful and helpful information about working with WMI (in the form of tasks). Some of the readers also asked me to give examples on VBScript as well (and not only VB.NET).
One should consider that WMI is being updated and enhanced almost every day. Microsoft is also integrating WMI directly into some of its products. With humble thanks to every reader who encouraged me to write more, I further extend the same series (but with a different naming scheme). I will be including much more useful information, both for developers and system administrators.
I keep on extending the same series as much as possible, covering almost all the aspects of WMI. I strongly suggest you go through my series on “WMI Programming with Visual Basic.NET” before reading this article. The series even covers “event handling” using WMI with Visual Basic .NET in the form of Windows Service.
For flexibility in retrieving WMI information (using VB.NET), I frequently used the following simple global routines which would help me to work with other areas of development very easily.
Public Sub addRow(ByRef dt As DataTable, ByVal p As String, ByVal v As String)
Dim dr As DataRow
dr = dt.NewRow
dr("Property") = p
dr("Value") = v
dt.Rows.Add(dr)
End Sub
Public Function getStructure() As DataTable
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("Property"))
dt.Columns.Add(New DataColumn("Value"))
Return dt
End Function
Two of my global routines are “getStructure” and “addRow”. Both are generally used if I have the “Property->value” scenario. “GetStructure” just creates a data table structure and “AddRow” just adds a data row for every data table passed to it. And similarly, I also have the following two, to work with “UserAccountInformation”.
Public Function getUserAccountStructure() As DataTable
Dim dt As New DataTable
dt.Columns.Add(New DataColumn("FullName"))
dt.Columns.Add(New DataColumn("Name"))
dt.Columns.Add(New DataColumn("Domain"))
dt.Columns.Add(New DataColumn("LocalAccount"))
Return dt
End Function
Public Sub addUserAccountRow(ByRef dt As DataTable, ByVal FullName As String, ByVal Name As String, ByVal Domain As String, ByVal LocalAccount As String)
Dim dr As DataRow
dr = dt.NewRow
dr("FullName") = FullName
dr("Name") = Name
dr("Domain") = Domain
dr("LocalAccount") = LocalAccount
dt.Rows.Add(dr)
End Sub
Next: Listing minimum server information using WMI >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee