当前位置: 首页 > 知识库问答 >
问题:

从Windows SDK生成相同的计算机硬件ID。(CHID)如computerhardwareids.exe

柯冯浩
2023-03-14

这个帖子应该是2014年第一个帖子和2017年第二个帖子的结束章节。

长话短说,你只需要知道微软视窗软件开发工具包包括一个叫做computerhardwareids.exe的程序,顾名思义,它为计算机生成(几个)硬件标识符,我想使用CHID算法复制。NET生成与此程序生成的相同的标识符。

这个程序可以在Windows 10(我正在使用的操作系统)上生成的代码列表如下:

我设法复制了除:0、1、2 和 12 之外的所有硬件 ID

我发现这四个有问题的标识符有一个共同点,即它们是唯一包含数值的标识符,可以附加到用于生成UUID的字符串中。请参阅此链接中的表格或阅读此列表:

>

  • 名称|长度|类型

    系统BIOS主要版本| BYTE |不同

    系统BIOS次要版本| BYTE |不同

    附件类型|字节|各不相同

    我认为这是一个明显的迹象,表明我不知道在构建用于生成UUID的字符串时如何处理这些数值。

    我不知道要在哪个WMI类中找到机柜类型值,但这无关紧要,因为我真的不在乎复制HardwareID-12/机柜类型值。但我希望能够复制HardwareID-0、HardwareID-1和HardwareID-2

    我已经知道从哪个WMI类获得HardwareID-0、HardwareID-1和HardwareID-2的BIOS主版本和次版本,但问题是,当我将这些BIOS值附加到用来生成UUID的字符串时,我得到的UUID与computerhardwareids.exe生成的完全不同。

    我的问题是:

    >

  • 我需要做什么才能为HardwareID-0、HardwareID-1和HardwareID-2复制完全相同的生成UUID?。

    也许我需要以特殊的方式处理这些数值,在将它们附加到生成 UUID 的字符串时应用一些我不知道的格式?

    请注意,我没有逆向工程的经验。

    这是我正在使用的代码,用VB.NET.在其当前状态下,我认为它是一个工作解决方案,可以复制(或者应该复制)与程序生成computerhardwareids.exe相同的计算机硬件ID,除了硬件ID 0、1、2和12,原因我已经解释过了。

    >

  • 计算机硬件id类型枚举

     ' https://learn.microsoft.com/en-us/windows-hardware/drivers/install/specifying-hardware-ids-for-a-computer
     Public Enum ComputerHardwareIdMicrosoftType
    
         ''' <summary>
         ''' HardwareID-0
         ''' <para></para>
         ''' Manufacturer + Family + Product Name + SKU Number + BIOS Vendor + BIOS Version + BIOS Major Release + BIOS Minor Release
         ''' </summary>
         HardwareID_0 = 0
    
         ''' <summary>
         ''' HardwareID-1
         ''' <para></para>
         ''' Manufacturer + Family + Product Name + BIOS Vendor + BIOS Version + BIOS Major Release + BIOS Minor Release
         ''' </summary>
         HardwareID_1 = 1
    
         ''' <summary>
         ''' HardwareID-2
         ''' <para></para>
         ''' Manufacturer + Product Name + BIOS Vendor + BIOS Version + BIOS Major Release + BIOS Minor Release
         ''' </summary>
         HardwareID_2 = 2
    
         ''' <summary>
         ''' HardwareID-3
         ''' <para></para>
         ''' Manufacturer + Family + Product Name + SKU Number + Baseboard Manufacturer + Baseboard Product
         ''' </summary>
         HardwareID_3 = 3
    
         ''' <summary>
         ''' HardwareID-4
         ''' <para></para>
         ''' Manufacturer + Family + Product Name + SKU Number
         ''' </summary>
         HardwareID_4 = 4
    
         ''' <summary>
         ''' HardwareID-5
         ''' <para></para>
         ''' Manufacturer + Family + Product Name
         ''' </summary>
         HardwareID_5 = 5
    
         ''' <summary>
         ''' HardwareID-6
         ''' <para></para>
         ''' Manufacturer + SKU Number + Baseboard Manufacturer + Baseboard Product
         ''' </summary>
         HardwareID_6 = 6
    
         ''' <summary>
         ''' HardwareID-7
         ''' <para></para>
         ''' Manufacturer + SKU Number
         ''' </summary>
         HardwareID_7 = 7
    
         ''' <summary>
         ''' HardwareID-8
         ''' <para></para>
         ''' Manufacturer + Product Name + Baseboard Manufacturer + Baseboard Product
         ''' </summary>
         HardwareID_8 = 8
    
         ''' <summary>
         ''' HardwareID-9
         ''' <para></para>
         ''' Manufacturer + Product Name
         ''' </summary>
         HardwareID_9 = 9
    
         ''' <summary>
         ''' HardwareID-10
         ''' <para></para>
         ''' Manufacturer + Family + Baseboard Manufacturer + Baseboard Product
         ''' </summary>
         HardwareID_10 = 10
    
         ''' <summary>
         ''' HardwareID-11
         ''' <para></para>
         ''' Manufacturer + Family
         ''' </summary>
         HardwareID_11 = 11
    
         ''' <summary>
         ''' HardwareID-12
         ''' <para></para>
         ''' Manufacturer + Enclosure Type
         ''' </summary>
         HardwareID_12 = 12
    
         ''' <summary>
         ''' HardwareID-13
         ''' <para></para>
         ''' Manufacturer + Baseboard Manufacturer + Baseboard Product
         ''' </summary>
         HardwareID_13 = 13
    
         ''' <summary>
         ''' HardwareID-14
         ''' <para></para>
         ''' Manufacturer
         ''' </summary>
         HardwareID_14 = 14
    
     End Enum
    

    计算机硬件ID生成方法:

     Public Shared Function GetComputerHardwareIdFromMicrosoftHwIdType(hwidType As ComputerHardwareIdMicrosoftType) As Guid
    
         Select Case hwidType
             Case Is < 0, Is > 14
                 Throw New InvalidEnumArgumentException(argumentName:=NameOf(hwidType), invalidValue:=hwidType, enumClass:=GetType(ComputerHardwareIdMicrosoftType))
    
         '' *************************************************************
         '' HARDWARE TYPE ID. 0, 1 AND 2 ARE NOT GIVING THE CORRECT GUID.
         '' *************************************************************
             Case 0, 1, 2, 12
                 Throw New NotImplementedException("This hardware id type is not implemented.")
         End Select
    
         ' Namespace used by 'computerhardwareids.exe' program included in the Windows SDK.
         ' https://stackoverflow.com/questions/25190906/get-hardware-ids-like-microsoft-does/43619888#43619888
         ' https://blogs.gnome.org/hughsie/2017/04/25/reverse-engineering-computerhardwareids-exe-with-winedbg/
         Dim namespaceUUID As Guid = Guid.Parse("70ffd812-4c7f-4c7d-0000-000000000000")
    
         ' Win32_ComputerSystem fields
         Dim manufacturer, family, productName, skuNumber As String
    
         ' Win32_BaseBoard fields
         Dim baseBoardManufacturer, baseBoardProduct As String
    
         ' Win32_BIOS fields
         Dim biosVendor, biosVersion, biosMajorRelease, biosMinorRelease As String
    
         ' Retrieve computer info.
         Using mos As New Management.ManagementObjectSearcher()
    
             ' Win32_ComputerSystem
             mos.Query.QueryString = "select Manufacturer,Model,SystemFamily,SystemSKUNumber from Win32_ComputerSystem"
             Using systemInfo As Management.ManagementObject = mos.Get(0)
                 manufacturer = CStr(systemInfo.Properties("Manufacturer").Value).Trim()
                 productName = CStr(systemInfo.Properties("Model").Value).Trim()
                 family = CStr(systemInfo.Properties("SystemFamily").Value).Trim()
                 skuNumber = CStr(systemInfo.Properties("SystemSKUNumber").Value).Trim()
             End Using
    
             ' Win32_BaseBoard
             mos.Query.QueryString = "select Manufacturer,Product from Win32_BaseBoard"
             Using baseBoardInfo As Management.ManagementObject = mos.Get(0)
                 baseBoardManufacturer = CStr(baseBoardInfo.Properties("Manufacturer").Value).Trim()
                 baseBoardProduct = CStr(baseBoardInfo.Properties("Product").Value).Trim()
             End Using
    
             ' Win32_BIOS
             mos.Query.QueryString = "select Manufacturer,SMBIOSBIOSVersion,SystemBiosMajorVersion,SystemBiosMinorVersion from Win32_BIOS"
             Using biosInfo As Management.ManagementObject = mos.Get(0)
                 biosVendor = CStr(biosInfo.Properties("Manufacturer").Value).Trim()
                 biosVersion = CStr(biosInfo.Properties("SMBIOSBIOSVersion").Value).Trim()
                 biosMajorRelease = CStr(biosInfo.Properties("SystemBiosMajorVersion").Value).Trim()
                 biosMinorRelease = CStr(biosInfo.Properties("SystemBiosMinorVersion").Value).Trim()
             End Using
    
         End Using
    
     #If DEBUG Then
         ' Console.WriteLine($"{NameOf(manufacturer)}          = {manufacturer}")
         ' Console.WriteLine($"{NameOf(productName)}           = {productName}")
         ' Console.WriteLine($"{NameOf(family)}                = {family}")
         ' Console.WriteLine($"{NameOf(skuNumber)}             = {skuNumber}")
         ' Console.WriteLine($"{NameOf(baseBoardManufacturer)} = {baseBoardManufacturer}")
         ' Console.WriteLine($"{NameOf(baseBoardProduct)}      = {baseBoardProduct}")
         ' Console.WriteLine($"{NameOf(biosVendor)}            = {biosVendor}")
         ' Console.WriteLine($"{NameOf(biosVersion)}           = {biosVersion}")
         ' Console.WriteLine($"{NameOf(biosMajorRelease)}      = {biosMajorRelease}")
         ' Console.WriteLine($"{NameOf(biosMinorRelease)}      = {biosMinorRelease}")
     #End If
    
         Dim stringToHash As String = String.Empty
    
         Select Case hwidType
    
             Case ComputerHardwareIdMicrosoftType.HardwareID_0
                 stringToHash = $"{manufacturer}&{family}&{productName}&{skuNumber}&{biosVendor}&{biosVersion}&{biosMajorRelease}&{biosMinorRelease}"
    
             Case ComputerHardwareIdMicrosoftType.HardwareID_1
                 stringToHash = $"{manufacturer}&{family}&{productName}&{biosVendor}&{biosVersion}&{biosMajorRelease}&{biosMinorRelease}"
    
             Case ComputerHardwareIdMicrosoftType.HardwareID_2
                 stringToHash = $"{manufacturer}&{productName}&{biosVendor}&{biosVersion}&{biosMajorRelease}&{biosMinorRelease}"
    
             Case ComputerHardwareIdMicrosoftType.HardwareID_3
                 stringToHash = $"{manufacturer}&{family}&{productName}&{skuNumber}&{baseBoardManufacturer}&{baseBoardProduct}"
    
             Case ComputerHardwareIdMicrosoftType.HardwareID_4
                 stringToHash = $"{manufacturer}&{family}&{productName}&{skuNumber}"
    
             Case ComputerHardwareIdMicrosoftType.HardwareID_5
                 stringToHash = $"{manufacturer}&{family}&{productName}"
    
             Case ComputerHardwareIdMicrosoftType.HardwareID_6
                 stringToHash = $"{manufacturer}&{skuNumber}&{baseBoardManufacturer}&{baseBoardProduct}"
    
             Case ComputerHardwareIdMicrosoftType.HardwareID_7
                 stringToHash = $"{manufacturer}&{skuNumber}"
    
             Case ComputerHardwareIdMicrosoftType.HardwareID_8
                 stringToHash = $"{manufacturer}&{productName}&{baseBoardManufacturer}&{baseBoardProduct}"
    
             Case ComputerHardwareIdMicrosoftType.HardwareID_9
                 stringToHash = $"{manufacturer}&{productName}"
    
             Case ComputerHardwareIdMicrosoftType.HardwareID_10
                 stringToHash = $"{manufacturer}&{family}&{baseBoardManufacturer}&{baseBoardProduct}"
    
             Case ComputerHardwareIdMicrosoftType.HardwareID_11
                 stringToHash = $"{manufacturer}&{family}"
    
             Case ComputerHardwareIdMicrosoftType.HardwareID_13
                 stringToHash = $"{manufacturer}&{baseBoardManufacturer}&{baseBoardProduct}"
    
             Case ComputerHardwareIdMicrosoftType.HardwareID_14
                 stringToHash = manufacturer
    
         End Select
    
         ' Creates a name-based UUID using the algorithm from RFC 4122 §4.3.
         ' https://stackoverflow.com/questions/61267254/generating-uuid-based-on-strings
         Dim generateGuidDelegate As Func(Of Guid, String, Guid) =
             Function(namespaceId As Guid, name As String) As Guid
    
                 ' Converts a GUID (expressed as a byte array) to/from network order (MSB-first).
                 Dim swapByteOrderDelegate As New Action(Of Byte())(
                     Sub(ByVal guid() As Byte)
                         Dim temp As Byte = guid(0)
                         guid(0) = guid(3)
                         guid(3) = temp
    
                         temp = guid(1)
                         guid(1) = guid(2)
                         guid(2) = temp
    
                         temp = guid(4)
                         guid(4) = guid(5)
                         guid(5) = temp
    
                         temp = guid(6)
                         guid(6) = guid(7)
                         guid(7) = temp
                     End Sub)
    
                 ' Convert the name to a sequence of octets (as defined by the standard or conventions of its namespace) (step 3).
                 Dim nameBytes() As Byte = Encoding.Unicode.GetBytes(name)
    
                 ' Convert the namespace UUID to network order (step 3).
                 Dim namespaceBytes() As Byte = namespaceId.ToByteArray()
                 swapByteOrderDelegate.Invoke(namespaceBytes)
    
                 ' Compute the hash of the name space ID concatenated with the name (step 4).
                 Dim hash As Byte()
                 Using algorithm As HashAlgorithm = SHA1.Create()
                     algorithm.TransformBlock(namespaceBytes, 0, namespaceBytes.Length, Nothing, 0)
                     algorithm.TransformFinalBlock(nameBytes, 0, nameBytes.Length)
                     hash = algorithm.Hash
                 End Using
    
                 ' Most bytes from the hash are copied straight to the bytes of the new GUID (steps 5-7, 9, 11-12).
                 Dim newGuid(15) As Byte
                 Array.Copy(hash, 0, newGuid, 0, 16)
    
                 ' Set the four most significant bits (bits 12 through 15) of the time_hi_and_version field
                 ' to the appropriate 4-bit version number from Section 4.1.3 (step 8).
                 newGuid(6) = CByte((newGuid(6) And &HF) Or (5 << 4))
    
                 ' Set the two most significant bits (bits 6 and 7) of the clock_seq_hi_and_reserved
                 ' to zero and one, respectively (step 10).
                 newGuid(8) = CByte((newGuid(8) And &H3F) Or &H80)
    
                 ' Convert the resulting UUID to local byte order (step 13).
                 swapByteOrderDelegate.Invoke(newGuid)
                 Return New Guid(newGuid)
             End Function
    
         Return generateGuidDelegate.Invoke(namespaceUUID, stringToHash)
    
     End Function
    

    用法示例:

     'Console.WriteLine($"{{{GetComputerHardwareIdFromMicrosoftHwIdType(0)}}}    <- Manufacturer + Family + ProductName + SKUNumber + BIOS Vendor + BIOS Version + BIOS Major Release + BIOS Minor Release")
     'Console.WriteLine($"{{{GetComputerHardwareIdFromMicrosoftHwIdType(1)}}}    <- Manufacturer + Family + ProductName + BIOS Vendor + BIOS Version + BIOS Major Release + BIOS Minor Release")
     'Console.WriteLine($"{{{GetComputerHardwareIdFromMicrosoftHwIdType(2)}}}    <- Manufacturer + ProductName + BIOS Vendor + BIOS Version + BIOS Major Release + BIOS Minor Release")
     Console.WriteLine($"{{{GetComputerHardwareIdFromMicrosoftHwIdType(3)}}}    <- Manufacturer + Family + ProductName + SKUNumber + Baseboard Manufacturer + Baseboard Product")
     Console.WriteLine($"{{{GetComputerHardwareIdFromMicrosoftHwIdType(4)}}}    <- Manufacturer + Family + ProductName + SKUNumber")
     Console.WriteLine($"{{{GetComputerHardwareIdFromMicrosoftHwIdType(5)}}}    <- Manufacturer + Family + ProductName")
     Console.WriteLine($"{{{GetComputerHardwareIdFromMicrosoftHwIdType(6)}}}    <- Manufacturer + SKUNumber + Baseboard Manufacturer + Baseboard Product")
     Console.WriteLine($"{{{GetComputerHardwareIdFromMicrosoftHwIdType(7)}}}    <- Manufacturer + SKUNumber")
     Console.WriteLine($"{{{GetComputerHardwareIdFromMicrosoftHwIdType(8)}}}    <- Manufacturer + ProductName + Baseboard Manufacturer + Baseboard Product")
     Console.WriteLine($"{{{GetComputerHardwareIdFromMicrosoftHwIdType(9)}}}    <- Manufacturer + ProductName")
     Console.WriteLine($"{{{GetComputerHardwareIdFromMicrosoftHwIdType(10)}}}    <- Manufacturer + Family + Baseboard Manufacturer + Baseboard Product")
     Console.WriteLine($"{{{GetComputerHardwareIdFromMicrosoftHwIdType(11)}}}    <- Manufacturer + Family")
     Console.WriteLine($"{{{GetComputerHardwareIdFromMicrosoftHwIdType(13)}}}    <- Manufacturer + Baseboard Manufacturer + Baseboard Product")
     Console.WriteLine($"{{{GetComputerHardwareIdFromMicrosoftHwIdType(14)}}}    <- Manufacturer")
    
  • 共有1个答案

    连俊智
    2023-03-14

    通过反复尝试可能的格式,我发现(字节类型的)数值必须转换为十六进制,并且必须使用小写。

    因此,为了复制硬件Id 0、1、2,我只需要对我在主帖子中发布的源代码进行以下更改:

    biosMajorRelease = CByte(biosInfo.Properties("SystemBiosMajorVersion").Value).ToString("X2").ToLower()
    biosMinorRelease = CByte(biosInfo.Properties("SystemBiosMinorVersion").Value).ToString("X2").ToLower()
    

    当然,删除 NotImplementException 行。

    现在,代码可以获取除硬件ID-12之外的所有硬件ID,因为我不知道在哪个WMI类中找到En

    但这并不重要。我有14个孩子中的13个在工作,我认为这是一个非常好的比率,最终可以说这是一个复制computerhardwareids.exe所做的完整的管理解决方案,尽管我没有在我的电脑上测试它。

     类似资料:
    • 不管是台式机还是笔记本,它们内部都有一块电路板,上面密密麻麻地布满了大小不一的电子器件,包括CPU、内存条、网卡、各种插槽和接口等,这就是“主板”,如下图所示。 这张图片主要让读者了解主板的构造,你不必理解图片中各个晦涩的名词。 图1:计算机主板CPU CPU (Central Processing Unit) 就是“中央处理器”,是计算机的大脑,负责计算、思考、处理数据、控制其他设备等,没有CP

    • 问题内容: 我需要从单台PC生成唯一的代码,我的软件将通过许可证进行分发,并且我需要在本地识别环境并将此代码发送到服务器。我不想在服务器上保留一个序列号,并且每个客户端都收到一个序列号,我试图从NetworkInterfaces读取MAC地址,但并不安全,用户可以轻松更改MAC地址。我认为最好的方法是读取主板序列号,但直到现在我还没有找到方法。有什么建议吗? 问题答案: 您的软件值多少钱? 目标市

    • 问题内容: 我正在尝试生成特定计算机唯一的ID。该ID不会随机生成。这将基于计算,以便为计算机A生成的ID将是固定的,并且对于计算机A是唯一的。每次在计算机A上执行程序时,它将继续生成相同的ID,并且在另一台计算机上执行时,它将生成该计算机唯一的另一个ID。这是为了确保两台​​计算机没有相同的ID。 我的挑战: 为了使我的程序能够生成计算机唯一的ID,它需要基于执行该计算机的计算机唯一的种子来执行

    • 如何在cmd上运行csr生成命令。exe openssl req-节点-newkey rsa: 2048-keyoutwww_mydomain_com.key-outwww_mydomain_com.csr-subj"/C=BB/ST=CCC/L=DDD/O=EEE。/OU=IT/CN=mydomain.com"

    • 问题内容: 有没有一种方法可以在SQL Server中生成具有定义的字符数的 随机 base36标识符? 我已经搜索并找到了许多将base 36转换为int,反之亦然的示例,但不是随机生成唯一ID的示例。 问题答案: 该解决方案有点冗长,但可以正常使用,并且可以轻松地适应各种需求。这是一些示例输出: 请注意,您需要创建一个视图来包装UDF内不允许使用的RAND。因此,此解决方案需要两个数据库对象,

    • 这里需要说明一下,笔者不建议在Windows环境下进行深度学习的研究,一方面是因为Windows所对应的框架搭建的依赖过多,社区设定不完全;另一方面,Linux系统下对显卡支持、内存释放以及存储空间调整等硬件功能支持较好。如果您对Linux环境感到陌生,并且大多数开发环境在Windows下更方便操作的话,希望这篇文章对您会有帮助。 **由于Keras默认以Tensorflow为后端,且Theano