Account information using WMI

Using WMI we can check the account information from the local computer. Here we use the Win32_Account WMI class to iterate through the available properties of that class.

From MSDN:

The Win32_Account abstract WMI class contains information about user accounts and group accounts known to the computer system running Windows. User or group names recognized by a Windows NT domain are descendants (or members) of this class.

The following function will grab all the properties from the Win32_Account class using WQL. We use a For Each Loop and display the properties for each local account.

Sample usage

Function GetAccountInfo()

Dim objWMI As Object
Dim accounts As Object
Dim account As Object

  Set objWMI = GetWMIService

  Set accounts = objWMI.ExecQuery("Select * from Win32_Account")

  For Each account In accounts
    Debug.Print account.Caption
    Debug.Print account.Description
    Debug.Print account.Domain
    Debug.Print account.InstallDate
    Debug.Print account.LocalAccount
    Debug.Print account.Name
    Debug.Print account.SID
    Debug.Print account.SIDType
    Debug.Print account.Status
  Next account

End Function

Function GetWMIService() As Object
' http://msdn.microsoft.com/en-us/library/aa394586(VS.85).aspx
Dim strComputer As String

  strComputer = "."

  Set GetWMIService = GetObject("winmgmts:" _
                              & "{impersonationLevel=impersonate}!\\" _
                              & strComputer & "\root\cimv2")
End Function

Site last updated: May 17, 2012

Random Data Generator