Link to home
Start Free TrialLog in
Avatar of pcorreya
pcorreya

asked on

api call to get serial number of pc

I believe there is some way to find out the serial number of your computer programatically. Is there some api call available for this ?
Avatar of Bhaskar Ganapathe
Bhaskar Ganapathe
Flag of India image

private static extern long GetVolumeInformation(string PathName, StringBuilder VolumeNameBuffer, UInt32 VolumeNameSize, ref UInt32 VolumeSerialNumber, ref UInt32 MaximumComponentLength, ref UInt32 FileSystemFlags, StringBuilder FileSystemNameBuffer, UInt32 FileSystemNameSize)

Are you looking for Volume's serial number or Mother board's serial no?

bhaspup
Avatar of pcorreya
pcorreya

ASKER

It is the serial no of the computer which i believe is in the bios

Thanks
Patrick
The serial number (or assest tag) of the computer is usually available via Windows Management Instrumentation (WMI).

Here is an example (in VB.Net) that demonstrates the concepts:

Imports System
Imports System.Management
Imports System.Windows.Forms

Namespace WMISample

    Public Class MyWMIQuery

        Public Overloads Shared Function Main() As Integer

            Try
                Dim searcher As New ManagementObjectSearcher( _
                    "root\CIMV2", _
                    "SELECT * FROM Win32_ComputerSystemProduct")

                For Each queryObj As ManagementObject in searcher.Get()

                    Console.WriteLine("-----------------------------------")
                    Console.WriteLine("Win32_ComputerSystemProduct instance")
                    Console.WriteLine("-----------------------------------")
                    Console.WriteLine("Caption: {0}", queryObj("Caption"))
                    Console.WriteLine("IdentifyingNumber: {0}", queryObj("IdentifyingNumber"))
                    Console.WriteLine("Name: {0}", queryObj("Name"))
                Next
            Catch err As ManagementException
                MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
            End Try
        End Function
    End Class
End Namespace
How do i make this work in a vb application. Is this is a windows api call ?
ASKER CERTIFIED SOLUTION
Avatar of graye
graye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial