Click here to Skip to main content
11,431,829 members (63,675 online)
Click here to Skip to main content
Technical Blog

Getting hardware and software details of the computers in your domain

, 17 Apr 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Win32 classes can be used as shown in the simple example below to get the hardware and software specs of a computer.

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

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:

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)

Share

About the Author

Morris Bahrami
Architect
Australia Australia
I have over 17 years of experience in software development in a variety of fields. For last 7 years the emphasis has been mostly on .NET technology (C# and VB.NET) which includes WPF, WCF and ASP.NET AJAX. Also have SQL Server experience including SSIS and SSRS. My blog (http://morrisbahrami.blogspot.com) has a collection of tips and general info for Microsoft Developers.

Comments and Discussions

 
General5 Pin
Lloyd Atkinson17-Apr-11 12:49
memberLloyd Atkinson17-Apr-11 12:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150428.2 | Last Updated 17 Apr 2011
Article Copyright 2011 by Morris Bahrami
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid