Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, February 15, 2017 7:09 AM
Hi Every One,
I want to know how to retrieve cpu or mother board serial number, or any hardware unique number to attach with my project with a login form, so that the user cannot use on other systems.
Thanks
Regards: Hammad
All replies (18)
Thursday, February 16, 2017 2:47 PM ✅Answered
This thread may be helpful.
Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
Friday, February 17, 2017 7:07 AM ✅Answered
Hi Hammad Xatti,
Thank you for posting here.
Also see this thread, get the serial of hardware with WMI (Such as motherboard, Hard and CPU).
Hope it will be helpful to you.
Best Regards,
Neda Zhang
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].
Wednesday, February 15, 2017 7:56 AM
I want to know how to retrieve cpu or mother board serial number, or any hardware unique number to attach with my project with a login form, so that the user cannot use on other systems.
You can query this and get any number of results. for example:
http://stackoverflow.com/questions/99880/generating-a-unique-machine-id
But you also need to consider how you will prevent the user from simply changing your software to match their machine.
Wednesday, February 15, 2017 8:10 AM
The code below will find the motherboard serial no. and CPU Id
You need two buttons on a form (Button1 & Button2) and two listboxes (listbox1 & listbox2)
You also need to set a reference to system.management
Imports System.Management
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Retrieve MortherBoard information
Dim searcher As ManagementObjectSearcher = _
New ManagementObjectSearcher("select * from Win32_BaseBoard")
For Each oReturn As ManagementObject In searcher.Get()
ListBox1.Items.Add( _
"MortherBoard Serial No." & Constants.vbTab & ": " & oReturn("SerialNumber").ToString)
Next oReturn
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'Retrieve CPU Id
Dim searcher As ManagementObjectSearcher = _
New ManagementObjectSearcher("select * from Win32_Processor")
For Each oReturn As ManagementObject In searcher.Get()
ListBox2.Items.Add("CPU ID" & Constants.vbTab & ": " & oReturn("ProcessorId").ToString)
Next oReturn
End Sub
End Class
Wednesday, February 15, 2017 8:53 AM
Hi Every One,
I want to know how to retrieve cpu or mother board serial number, or any hardware unique number to attach with my project with a login form, so that the user cannot use on other systems.
Thanks
Regards: Hammad
Hammad,
There are endless discussions around this subject on Internet. You are surely not the first one who thinks this is a solution.
However, at the end the result is always that it is only a solution for software which is sold with the Mother Board and those CPU's or Motherboard has somewhere a serialnumber which is not only available by reading with eyes.
Motherboards which have a rom with a serialnumber are rare, the same with CPU's where the serialnumber is a part of the making process.
Therefore the question, are you making motherboards or cpu"s.
Success
Cor
Wednesday, February 15, 2017 11:02 AM
Cor
So what should be the solution,to protect software? So that except that user no one should be allowed to copy or use...
Wednesday, February 15, 2017 11:04 AM
Dear AndyNakamura i already try this piece of code but its not working?
Wednesday, February 15, 2017 11:37 AM
Do you get any error messages?
Do you get red squiggly lines under the code?
Did you set the reference to system.management ie
click project,
In the drop down menu click 'Add reference'
Highlight 'Framework' on the left hand side
in the list in the right hand pane scroll down to find 'System.management'
As you hover your mouse pointer over it a box will appear. Click that box to give it a tick and click ok
Wednesday, February 15, 2017 11:37 AM
Simply search on Internet, you will see there is not one fail proof.
Your way of hardware protection has only led that customers did not buy that software anymore because when there are hardware problems, the repair of the hardware can cause the program does not run anymore.
However, this is what is lately used.
https://www.bu.edu/tech/about/security-resources/bestpractice/auth/
Success
Cor
Wednesday, February 15, 2017 12:51 PM
Hammad,
Let me know if the following is (or is part of) what you want:
I'll let you work out whether or not to use it.
If this is what you want though, let me know and I'll put it together and post it so that you can use it.
"One who has no vices also has no virtues..."
Wednesday, February 15, 2017 12:51 PM
AndyNakamura Thanks for your suggestion but i need that code which returns the serial number of the cpu or mother board serial number so that i put a condition if that serial number matches with that number than the program should work otherwise No.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Label1.Text = cpuid()
Dim oMother As Object = Nothing
Dim sMBserial As String = Nothing
Dim oWMG As Object = GetObject("WinMgmts:")
oMother = oWMG.InstancesOf("Win32_BaseBoard")
For Each obj As Object In oMother
sMBserial += obj.SerialNumber
'if you have more than one motherboard separate with comma
'it could happen :p
If oMother.count > 1 Then sMBserial += ","
Next
MsgBox(sMBserial)
End Sub
Above code i already use but it returns only"TYPE-2 Board Serial Number"
Wednesday, February 15, 2017 1:21 PM
Hammad,
This is put together in a way that it's meant to be its own assembly (a class library that will create a .dll file).
Be sure to add a reference to System.Management then the following will work for the library's code:
Option Strict On
Option Explicit On
Option Infer Off
Imports System.Management
Imports System.Security.Cryptography
Namespace Hardware
Public Class ComputerHardware
Public Shared Function GetID() As String
Return HardwareSimpleData.GetID
End Function
End Class
Friend Class HardwareSimpleData
Private Sub New()
End Sub
Public Shared Function GetID() As String
Dim retVal As String = Nothing
Try
Dim hi As HardwareInfo = GetSuccinctInfo()
If hi IsNot Nothing Then
Dim sb As New System.Text.StringBuilder
sb.Append(hi.BiosManufacturer)
sb.Append(hi.BiosSerialNumber)
sb.Append(hi.BiosVersion)
sb.Append(hi.MotherboardManufacturer)
sb.Append(hi.MotherboardProduct)
sb.Append(hi.MotherboardSerialNumber)
retVal = GetHardwareHash(sb.ToString)
End If
Catch ex As Exception
Throw
End Try
Return retVal
End Function
Private Shared Function GetSuccinctInfo() As HardwareInfo
Dim retVal As New HardwareInfo
Try
Using mos As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_BaseBoard")
For Each mo As ManagementObject In mos.Get()
With retVal
Try
.MotherboardManufacturer = mo.GetPropertyValue("Manufacturer").ToString
Catch ex As Exception
.MotherboardManufacturer = "Unknown"
End Try
Try
.MotherboardSerialNumber = mo.GetPropertyValue("SerialNumber").ToString
Catch ex As Exception
.MotherboardSerialNumber = "Unknown"
End Try
Try
.MotherboardProduct = mo.GetPropertyValue("Product").ToString
Catch ex As Exception
.MotherboardProduct = "Unknown"
End Try
End With
Exit For
Next
End Using
Using mos As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_BIOS")
For Each mo As ManagementObject In mos.Get()
With retVal
Try
.BiosManufacturer = mo.GetPropertyValue("Manufacturer").ToString
Catch ex As Exception
.BiosManufacturer = "Unknown"
End Try
Try
.BiosSerialNumber = mo.GetPropertyValue("SerialNumber").ToString
Catch ex As Exception
.BiosSerialNumber = "Unknown"
End Try
Try
.BiosVersion = mo.GetPropertyValue("Version").ToString
Catch ex As Exception
.BiosVersion = "Unknown"
End Try
End With
Exit For
Next
End Using
Catch ex As Exception
Throw
End Try
Return retVal
End Function
Private Shared Function GetHardwareHash(ByVal data As String) As String
Dim retVal As String = Nothing
Try
Dim convertedToBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(data)
Dim hashType As HashAlgorithm = New SHA256Managed()
Dim hashBytes As Byte() = hashType.ComputeHash(convertedToBytes)
retVal = Convert.ToBase64String(hashBytes)
Catch ex As Exception
Throw
End Try
Return retVal
End Function
Public Class HardwareInfo
Public Property MotherboardManufacturer As String
Public Property MotherboardSerialNumber As String
Public Property MotherboardProduct As String
Public Property BiosManufacturer As String
Public Property BiosSerialNumber As String
Public Property BiosVersion As String
End Class
End Class
End Namespace
Build it and it will create a .dll file. To test it, in Form1 I used the following:
Option Strict On
Option Explicit On
Option Infer Off
Imports SCHI.Hardware
Public Class Form1
Private Sub Form1_Load(sender As System.Object, _
e As System.EventArgs) _
Handles MyBase.Load
Dim computerID As String = ComputerHardware.GetID
Stop
End Sub
End Class
That then popped back with an "ID" as follows:
If you want, I'll zip up the project folder and upload for you.
***** EDIT *****
Please modify the private function; hashtype should be disposed or just use a Using block:
Private Shared Function GetHardwareHash(ByVal data As String) As String
Dim retVal As String = Nothing
Try
Dim convertedToBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(data)
Using hashType As HashAlgorithm = New SHA256Managed()
Dim hashBytes As Byte() = hashType.ComputeHash(convertedToBytes)
retVal = Convert.ToBase64String(hashBytes)
End Using
Catch ex As Exception
Throw
End Try
Return retVal
End Function
"One who has no vices also has no virtues..."
Wednesday, February 15, 2017 1:27 PM
Hi
Button 1 should retrieve the motherboard number
Button2 should retrieve the CPU number
If I run either your code or mine on my computer I get the serial number of the board.
Maybe there is no serial number as such on yours?
Wednesday, February 15, 2017 1:32 PM
Frank L.Smith
Thanks alot but kindly send me the full project...so that i can try
Wednesday, February 15, 2017 1:42 PM
Frank L.Smith
Thanks alot but kindly send me the full project...so that i can try
https://fls.exavault.com/share/view/fc1x-7fmb6oyy
That's a zip file with only one entry: The project folder.
Download that somewhere on your computer then extract it and open it in Visual Studio. You'll be prompted to convert it so just follow the prompts and it should work as it is.
Let me know please.
"One who has no vices also has no virtues..."
Thursday, February 16, 2017 6:32 AM
Frank
It cannot be download...some message box like "some sites do not allow requesting the same file"
try to upload in any other site.
Thanks
Thursday, February 16, 2017 9:39 AM
I thought why don't I give that sample we have since around 2004 on our website.
However, I know again. Microsoft made a freeware tool for this years ago.
https://www.microsoft.com/en-us/download/details.aspx?id=8572
Success
Cor
Thursday, February 16, 2017 10:50 AM
Frank
It cannot be download...some message box like "some sites do not allow requesting the same file"
try to upload in any other site.
Thanks
I just downloaded it as a test and it downloaded fine.
Many people here have downloaded files from that (it's an FTP site), so try again - it should work fine.
"One who has no vices also has no virtues..."