vb.net 如何获得PC唯一ID?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7550354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to get PC unique id?
提问by soclose
- What is the PC unique ID?
- How could we get the PC unqiue ID?
- Is it about Hard disk or motherboard?
- 什么是PC唯一ID?
- 我们如何获得PC唯一ID?
- 是关于硬盘还是主板?
I'd like to store PC ID in my window program. Please share me.
我想在我的窗口程序中存储 PC ID。请分享我。
回答by Sajitha Rathnayake
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
看这里
回答by dfrevert
Try this, it pulls the ID off the processor.
试试这个,它会从处理器中取出 ID。
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
回答by Laszlo the Wiz
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.
我假设您想生成一个对机器唯一的 ID。硬盘驱动器可能是最简单的方法,因为其他硬件过于多样化,无法设置检索序列号的方法。
Probably the easiest is to use the number that Windows generates for the hard drive.
可能最简单的方法是使用 Windows 为硬盘驱动器生成的编号。
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).
您可以在 HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices 下找到它,密钥名称为 \DosDevices\C:(假设 C: 驱动器是主系统驱动器 - 在某些非常罕见的情况下并非如此,但是您可以检查系统驱动器是什么并使用适当的密钥)。
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.htmlfor Windows. Or http://blog.granneman.com/2007/07/26/find-out-a-hard-drives-uuid/for Linux.
还有另一个与硬盘驱动器相关的数字,称为 UUID,您可以找到脚本来获取它。例如:适用于 Windows 的http://www.windowsnetworking.com/articles_tutorials/Deploying-Windows-7-Part18.html。或者http://blog.granneman.com/2007/07/26/find-out-a-hard-drives-uuid/对于 Linux。
I also found this article on retrieving the motherboard's serial number: Getting motherboard unique ID number thru vc++ programming
我还发现了这篇关于检索主板序列号的文章:通过 vc++ 编程获取主板唯一 ID 号
回答by Peter O.
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.
“PC 唯一 ID”通常是指硬件 ID,用于唯一标识计算机。例如,它们可用于跟踪计算机上的软件使用情况。
According to this question, the "motherboard id, processor id and bios id" "are the least likely to change".
根据这个问题,“主板 id、处理器 id 和 bios id”“最不可能改变”。
This questioncontains code to get such information in C#; I couldn't find any topics for VB.NET, unfortunately, but it should be easy to port.
此问题包含在 C# 中获取此类信息的代码;不幸的是,我找不到 VB.NET 的任何主题,但它应该很容易移植。