Reputation: 2783
I'd like to store PC ID in my window program. Please share me.
Upvotes: 5
Views: 31682
Reputation: 323
requires https://www.nuget.org/packages/System.Management/
System.Management 4.7.0
As you can see there is an "Unique Value" plus some special calculations. You can make this as hard as you can, but reverse engineering can ultimately expose this.
Better (but slower) version for computer ID (requires System.Management import and reference): Code:
Public Shared Function GetComputerID() As Long
Dim objMOS As New ManagementObjectSearcher("Select * From Win32_Processor")
For Each objMO As Management.ManagementObject In objMOS.Get
GetComputerID += objMO("ProcessorID").GetHashCode
Next
GetComputerID += My.Computer.Name.GetHashCode
End Function
Upvotes: 0
Reputation: 1728
This work for me
Private Function CpuId() As String
Dim computer As String = "."
Dim wmi As Object = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & _
computer & "\root\cimv2")
Dim processors As Object = wmi.ExecQuery("Select * from " & _
"Win32_Processor")
Dim cpu_ids As String = ""
For Each cpu As Object In processors
cpu_ids = cpu_ids & ", " & cpu.ProcessorId
Next cpu
If cpu_ids.Length > 0 Then cpu_ids = _
cpu_ids.Substring(2)
Return cpu_ids
End Function
see here
Upvotes: 6
Reputation: 32898
The "PC unique ID" normally means the hardware ID, used to uniquely identify a computer. For example, they can be used to track software use on computers.
According to this question, the "motherboard id, processor id and bios id" "are the least likely to change".
This question contains code to get such information in C#; I couldn't find any topics for VB.NET, unfortunately, but it should be easy to port.
Upvotes: 0
Reputation: 574
I assume that you want to generate an ID that is unique to the machine. Hard drive is probably the easiest approach because other hardware is too diverse to have a set way of retrieving their serial numbers.
Probably the easiest is to use the number that Windows generates for the hard drive.
You can find it under HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices and the key name is \DosDevices\C: (assuming that the C: drive is the main system drive - which is not the case in some very rare cases, but then you can check for what the system drive is and use the appropriate key).
There's another number associated with Hard drives called UUID and you can find scripts to get that. For example: http://www.windowsnetworking.com/articles_tutorials/Deploying-Windows-7-Part18.html for Windows. Or http://blog.granneman.com/2007/07/26/find-out-a-hard-drives-uuid/ for Linux.
I also found this article on retrieving the motherboard's serial number: Getting motherboard unique ID number thru vc++ programming
Upvotes: 0
Reputation: 366
Try this, it pulls the ID off the processor.
Dim win32MgmtClass as System.Management.ManagementClass
win32MgmtClass = new System.Management.ManagementClass("Win32_Processor")
Dim processors as System.Management.ManagementObjectCollection
processors = win32MgmtClass.GetInstances()
For Each processor As System.Management.ManagementObject In processors
MessageBox.Show(processor("ProcessorID").ToString())
Next
Upvotes: 2