Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VB

Getting Hardware and Software Details of the Computers in your Domain

5.00/5 (1 vote)
17 Apr 2011CPOL 12.5K  
How to get hardware and software details of the computers in your domain

Win32 classes can be used as shown in the simple example below to get the hardware and software specs of a computer:

VB
Private Sub GetOperatingSystemDetails()
    Dim mos As ManagementObjectSearcher = _
        New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")

    For Each mo As ManagementObject In mos.Get
        Dim OsName As String = mo("name")
        Dim Version As String = mo("version") 
        Dim SerialNumber As String = mo("serialNumber") 
    Next
End Sub

In the above example, we only used one of the Win32 classes (Win32_OpratingSystem) and for that, we only read three properties out of more than 60.

To use this example code, you need to add a reference to System.Management in your project and import that.

In a previous post, A VB.NET program to list all computers in your domain, I showed how you can get the list of computers in your domain. You can combine traversing through computers in your domain as shown in that post with the use of Win32 classes to get the details of those computers. To run Win32 related commands on remote computers, you need to have the required privilege. In addition to that, those computers also need to have RPC and WMI services running on them.

The following example shows how to read the above three values we had for the first example from another computer in your domain:

VB
Public Sub GetOperatingSystemDetails (ByVal computer As String)
    Dim options As ConnectionOptions = New ConnectionOptions()
    options.Username = "USERNAME" ' Select User Name
    options.Password = "PASSWORD" ' Select password
    ' You can also specify Kerberos instead of ntlm below
    options.Authority = "ntlmdomain:Domain" ' Select Domain

    Dim scope As ManagementScope = _
        New ManagementScope("\\" & computer & "\root\cimv2", options)

    scope.Connect()

    Dim query As ObjectQuery = _
        New ObjectQuery("SELECT * FROM Win32_OperatingSystem")
    Dim mos As ManagementObjectSearcher = _
        New ManagementObjectSearcher(scope, query)
    Dim queryCollection As ManagementObjectCollection = mos.Get

    For Each mo As ManagementObject In queryCollection
        Dim OsName As String = mo("name")
        Dim Version As String = mo("version")
        Dim SerialNumber As String = mo("serialNumber")
    Next
End Sub

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)