Search code examples
hardwarevisual-studio-express

How to get hardware print?


Can someone tell me how to get the hardware print of my computer, on VB 2010 express, or where and how is that stored? Thanks in advance.


Solution

  • The best way to figure out what hardware is attached to your computer is to use WMI to get the information. Microsoft has created a tool that will create C#, VB.Net and VBScript sample code which you can run with the program and see what the values are, you can then add it to your program. This tool is called the WMI Code Creator. I would start out by exploring the Classes starting with Win32_


    Now that I know what you are trying to do I can be a little more specific. The WMI NameSpace you are needing is root\CIMV2 the Class is Win32_DiskDrive or Win32_PhysicalMedia and the Property is SerialNumber. I made a small console test app in Vb.net. It will print out the drive serialnumbers on your PC, if you need it in c# I can modify. There are also numerous other SO Questions about the same subject.

    Imports System
    Imports System.Management
    
    Module Module1
    
        Sub Main()
            For Each sn As String In GetDriveSerialNumber()
                Console.WriteLine(sn.Trim)
            Next
            Console.ReadLine()
        End Sub
    
        Function GetDriveSerialNumber() As List(Of String)
            Dim snList As List(Of String) = New List(Of String)
            Try
                Dim searcher As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_DiskDrive")
    
                For Each queryObj As ManagementObject In searcher.Get()
                    snList.Add(queryObj("SerialNumber").ToString())
                Next
            Catch err As ManagementException
                Throw
            End Try
            Return snList
        End Function
    
    End Module