Reputation: 45
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.
Upvotes: 2
Views: 23546
Reputation: 502
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
Upvotes: 3
Reputation: 2019
I found a little project online where they get:
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.
Upvotes: 10