2

I tried getting Hard disk and Motherboard Serial Number from my PC. It works good in Windows 7 and Above

But same code in CMD does not working for Windows XP. It Shows O.E.M to be filled or Returns Nothing

wmic diskdrive get name,serialnumber,model // This is cmd to get serial num

In Windows XP It Returns Error for serialnumber

wmic baseboard get product,Manufacturer,version,serialnumber // This is cmd to get MotherBoard serialnumber

In Windows XP and Win 8 it returns in serialnumber Error like "To be filled by O.E.M"

Am looking for Best Pc Unique Id , which can return id or serialnumber for any OS and should be unique..

Please help me

Thank You.

ram nainar
  • 45
  • 1
  • 1
  • 3
  • 1
    What do you need it for? Is this for a licensing feature, or just a unique client ID? Does it need to be consistent across OS upgrades or wipes? Does it need to be tamper-proof? – Roger Lipscombe Apr 14 '17 at 09:27

2 Answers2

10

I found a little project online where they get:

  • Processor ID
  • Motherboard ID
  • Volume serial ID
  • Mac address ID

They then hash it through MD5 but it is depreciated now so best bet is do the same and hash it through Sha512

First you'll need to import and reference if not done automatically:

Imports System.Management
Imports System.Security.Cryptography
Imports System.Text

Then the function get HWID (HardwareID)

Public Function Get_HWID() As String
    'Information Handler
    Dim hw As New clsComputerInfo
    'Decalre variables
    Dim hdd, cpu, mb, mac As String
    'Get all the values
    cpu = hw.GetProcessorId()
    hdd = hw.GetVolumeSerial("C")
    mb = hw.GetMotherBoardID()
    mac = hw.GetMACAddress()
    'Generate the hash
    Dim hwid As String = GenerateSHA512String(cpu & hdd & mb & mac)
    Return hwid
End Function

Function to generate Hash:

Public Shared Function GenerateSHA512String(ByVal inputString) As String
    Dim sha512 As SHA512 = SHA512Managed.Create()
    Dim bytes As Byte() = Encoding.UTF8.GetBytes(inputString)
    Dim hash As Byte() = sha512.ComputeHash(bytes)
    Dim stringBuilder As New StringBuilder()
    For i As Integer = 0 To hash.Length - 1
        stringBuilder.Append(hash(i).ToString("X2"))
    Next
    Return stringBuilder.ToString()
End Function

And finally Class to get the information:

Public Class clsComputerInfo
    Friend Function GetProcessorId() As String
        Dim strProcessorId As String = String.Empty
        Dim query As New SelectQuery("Win32_processor")
        Dim search As New ManagementObjectSearcher(query)
        Dim info As ManagementObject
        For Each info In search.Get()
            strProcessorId = info("processorId").ToString()
        Next
        Return strProcessorId
    End Function
    Friend Function GetMACAddress() As String
        Dim mc As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
        Dim moc As ManagementObjectCollection = mc.GetInstances()
        Dim MACAddress As String = String.Empty
        For Each mo As ManagementObject In moc
            If (MACAddress.Equals(String.Empty)) Then
                If CBool(mo("IPEnabled")) Then MACAddress = mo("MacAddress").ToString()
                mo.Dispose()
            End If
            MACAddress = MACAddress.Replace(":", String.Empty)
        Next
        Return MACAddress
    End Function
    Friend Function GetVolumeSerial(Optional ByVal strDriveLetter As String = "C") As String
        Dim disk As ManagementObject = New ManagementObject(String.Format("win32_logicaldisk.deviceid=""{0}:""", strDriveLetter))
        disk.Get()
        Return disk("VolumeSerialNumber").ToString()
    End Function
    Friend Function GetMotherBoardID() As String
        Dim strMotherBoardID As String = String.Empty
        Dim query As New SelectQuery("Win32_BaseBoard")
        Dim search As New ManagementObjectSearcher(query)
        Dim info As ManagementObject
        For Each info In search.Get()
            strMotherBoardID = info("SerialNumber").ToString()
        Next
        Return strMotherBoardID
    End Function
End Class

I reviewed the code of this project

Hope this can help you and please remember add the reference to Management

More Information:

Most common IDs used for HWID are: CPU ID and MAC address based hardware ID and Hard Drive serial number

HWID are not recommended as a licencing system as it isn't accurate and not practical if the user changes computer or formats the drives etc. It is more recommended to use a certificate system or more complex authentification.

Mederic
  • 1,949
  • 4
  • 19
  • 36
  • Tried Your Code ... Processor Id is common on some PC..... So it Failed , for mac address PC need Network adapter , so it failed , when i tried for getting motherboard serialnumber........it not works in win 8 – ram nainar Apr 14 '17 at 09:25
  • Did you **add the reference**.... and you don't understand here we combine all the values in one ID because no computer will have the 4 values added together the same .... I'm on windows 8 and it works fine. Try to understand the code instead of **copy pasting** – Mederic Apr 14 '17 at 09:35
  • Did you try to run your app as lower framework than 4.5 by a framework supported by XP... max XP supports is 4.0 and some don't go higher than 3.5 – Mederic Apr 14 '17 at 09:43
  • That unique id should not change dude .... if i format the system C: Volume serial number would change .... so the code might change next time...... so if i combine all these serial number.... c: volume serial number value may change at formatting and could change entire hwid next time.... – ram nainar Apr 14 '17 at 09:46
  • dude in deployment place we dont have network adapter in PC , so it will return null and in XP Motherboard serialnumber not works..... and processor id returns common id in some systems...... – ram nainar Apr 14 '17 at 09:53
  • 1
    @ramnainar you actually can get much info from motherboard in XP: [Video to teach you](https://www.youtube.com/watch?v=fK-jKWSDhrA) Furthermore most software companies don't use HWID as it is not reliable. the mostly used HWID are: **CPU ID** and **MAC address based hardware ID** and **Hard Drive serial number** you should think of creating a proper licencing system instead of something wobbly. and why bother having a HWID if you don't have a network car to communicate to a server. – Mederic Apr 14 '17 at 10:03
3

Remember Mac address and Volume serial can be change. Hence hardware will have unpredictable changes.
So use Processor and Motherboard ID so that hardware ID never changes.
So on these basis, you could modify @Mederic code as below:

'Get the MotherBoard ID
    Function GetMotherBoardID() As String
        Dim query As New SelectQuery("Win32_BaseBoard")
        Dim search As New ManagementObjectSearcher(query)
        For Each info As ManagementObject In search.Get()
            Return info("SerialNumber").ToString()
        Next
    End Function

'Get the Processor ID 
    Function GetProcessorId() As String
        Dim query As New SelectQuery("Win32_processor")
        Dim search As New ManagementObjectSearcher(query)
        Dim info As ManagementObject
        For Each info In search.Get()
            Return info("processorId").ToString()
        Next
    End Function

' Generate Hash  
    Function GenerateHash(ByVal input As String) As String
        Dim hash = New SHA1Managed().ComputeHash(Encoding.UTF8.GetBytes(input))
        Return String.Concat(hash.[Select](Function(b) b.ToString("x2")))
    End Function


'Now display Hardware ID
MessageBox.Show(GenerateHash(GetMotherBoardID() & GetProcessorId()))

Source code : Code file, Binary executable.

Processor ID not Unique for all computers but remain unchanged. refernce
Motherboard ID can't be changed. reference

Sorry IwontTell
  • 466
  • 10
  • 29