【问题标题】:how to get PC unique id?如何获得PC唯一ID?
【发布时间】:2011-11-24 21:46:53
【问题描述】:
  1. 什么是 PC 唯一 ID?
  2. 我们如何获得 PC 唯一 ID?
  3. 是硬盘还是主板?

我想将 PC ID 存储在我的窗口程序中。请分享给我。

【问题讨论】:

  • 这里没有讨论 VB 的具体实现,但确实描述了各种选项:stackoverflow.com/questions/671876/…
  • 没有“PC 唯一 ID”。一些PC部件有序列号,如CPU、硬盘、主板、网卡……但用户可以更换该部件,然后你会得到一个新的ID。尝试更具体地说明您的目标。
  • 为什么要为那台电脑存储一个唯一的 ID?你会用这个做什么?

标签: vb.net visual-studio-2005 unique-key


【解决方案1】:

这对我有用

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

here

【讨论】:

  • 这不是唯一的。我在不到 10 台计算机上尝试过,但我已经得到了重复
  • @RonaldPaguay 你还有什么发现吗?工作代码?
  • 没有。但是我从一个商业产品中获得了灵感,该产品考虑了几个部分。如果更改少于 30%,则视为同一台 PC。适用于我的用例。
【解决方案2】:

试试这个,它会从处理器中提取 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

【讨论】:

  • 在声明对 System.Management 和 System.Windows.Forms 的引用后在我的盒子上工作
【解决方案3】:

我假设您想要生成一个机器独有的 ID。硬盘驱动器可能是最简单的方法,因为其他硬件种类繁多,没有固定的方法来检索其序列号。

可能最简单的方法是使用 Windows 为硬盘生成的数字。

您可以在 HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices 下找到它 并且密钥名称是 \DosDevices\C: (假设 C: 驱动器是主系统驱动器 - 在极少数情况下并非如此,但是您可以检查系统驱动器是什么并使用适当的密钥)。

还有一个与硬盘相关的数字,称为 UUID,您可以找到脚本来获取它。例如:http://www.windowsnetworking.com/articles_tutorials/Deploying-Windows-7-Part18.html 用于 Windows。或http://blog.granneman.com/2007/07/26/find-out-a-hard-drives-uuid/ 用于 Linux。

我还找到了这篇关于找回主板序列号的文章:Getting motherboard unique ID number thru vc++ programming

【讨论】:

    【解决方案4】:

    “PC 唯一 ID”通常是指硬件 ID,用于唯一标识一台计算机。例如,它们可用于跟踪计算机上的软件使用情况。

    根据this question,“主板id、处理器id和bios id”“最不可能改变”。

    This question 包含在 C# 中获取此类信息的代码;不幸的是,我找不到任何 VB.NET 的主题,但它应该很容易移植。

    【讨论】:

    • 主板 ID 似乎不可靠。在我的系统上,wmic baseboard get serialnumber 返回一个明显伪造的数字。尽管wmic bios get serialnumber 确实 在我的笔记本电脑上返回了一个看起来合理的值,但我相信底层机器只要一只钉腿蚱蜢可以踢它。它可以很容易地设置为创建者和/或用户想要输入的任何 ID 的虚拟机。
    • 收回 ID 是“可靠的”。
    【解决方案5】:

    需要 https://www.nuget.org/packages/System.Management/

    System.Management 4.7.0

    如您所见,有一个“唯一值”以及一些特殊计算。你可以尽可能地做到这一点,但逆向工程最终会暴露这一点。

    计算机 ID 的更好(但更慢)版本(需要 System.Management 导入和引用): 代码:

        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
    

    【讨论】:

      猜你喜欢
      • 2016-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-12
      • 2011-05-12
      • 1970-01-01
      相关资源
      最近更新 更多