Listing/Modifying Server Information with Visual Basic.NET and VBScript Using WMI - How to retrieve all group information along with account information using WMI
(Page 4 of 5 )
The following VB.NET code would give you the information on all user groups available (whether or not the user group is part of a domain). It also includes user account information.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", _
"SELECT * FROM Win32_AccountSID")
Dim dt As DataTable = globals.getStructure()
Dim en As ManagementObjectEnumerator =
searcher.Get.GetEnumerator
While en.MoveNext
Dim queryObj As ManagementObject = en.Current
globals.addRow(dt, "User: ", queryObj("Element"))
End While
dt.AcceptChanges()
Me.DataGrid1.DataSource = dt
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for
WMI data: " & err.Message)
End Try
End Sub
You can achieve the same result by using VBScript code as follows:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_AccountSID",,48)
For Each objItem in colItems
Wscript.Echo "Element: " & objItem.Element
Next
One should note that I used different WMI classes and properties for different scenarios. You can get the full list of classes along with their properties and other documentation online at MSDN online. Hundreds of classes exist in WMI to fetch even the most in-depth information about your server.
Next: How to change your computer name using WMI >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee