Click here to Skip to main content
15,889,820 members
Articles / Programming Languages / Visual Basic

Getting Hardware and Software Details of the Computers in your Domain

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
17 Apr 2011CPOL 12.2K   2   1
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
This article was originally posted at http://morrisbahrami.blogspot.com/feeds/posts/default

License

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


Written By
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
LloydA11117-Apr-11 11:49
LloydA11117-Apr-11 11:49 

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

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