获取像Microsoft一样的硬件ID [英] Get Hardware IDs like Microsoft does

查看:335
本文介绍了获取像Microsoft一样的硬件ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows SDK中,有一个名为计算机硬件ID

In the Windows SDK there is a CLI tool named computerhardwareids

该工具返回各种GUID,以为特定情况选择适当的HardwareId.

The tool returns various GUIDs to select the proper HardwareId for the specific case.

这是在我的PC中返回此工具的输出:

This is the output that returns this tool in my PC:

Using the BIOS to gather information

Computer Information
--------------------

BIOS Vendor: American Megatrends Inc.
BIOS Version string: 1201
System BIOS Major Release: 4
System BIOS Minor Release: 6

System Manufacturer: To be filled by O.E.M.
System Family: To be filled by O.E.M.
System ProductName: To be filled by O.E.M.
SKU Number: SKU

Enclosure Type: 03 "Desktop"


Hardware IDs
------------
{a8670b03-1d98-5e95-ad4e-c64211eac9df}    <- Manufacturer + Family + ProductName + SKUNumber + BIOS Vendor + BIOS Version + BIOS Major Release + BIOS Minor Release
{01c6b2a2-a2b2-58e4-906d-4677639f1a42}    <- Manufacturer + Family + ProductName + BIOS Vendor + BIOS Version + BIOS Major Release + BIOS Minor Release
{dc5af3fe-c2de-539d-aafd-5061a1634723}    <- Manufacturer + ProductName + BIOS Vendor + BIOS Version + BIOS Major Release + BIOS Minor Release
{d78b474d-dee0-5412-bc9d-e9f7d7783df2}    <- Manufacturer + Family + ProductName + SKUNumber
{7ccbb6f1-9641-5f84-b00d-51ff218a4066}    <- Manufacturer + Family + ProductName
{5a127cba-be28-5d3b-84f0-0e450d266d97}    <- Manufacturer + SKUNumber
{6525c6e5-28e9-5f9c-abe4-20fd82504002}    <- Manufacturer + ProductName
{6525c6e5-28e9-5f9c-abe4-20fd82504002}    <- Manufacturer + Family
{482f3f58-6045-593a-9be4-611717ce4770}    <- Manufacturer + Enclosure Type
{11b4a036-3b64-5421-a372-22c07df10a4d}    <- Manufacturer


我想开发一个通用的使用功能,该功能应模仿该Microsoft工具的功能,并返回完全相同的HardwareIds (完全相同).


I would like to develop a generic use function that should mimic the functionality of that Microsoft tool, returning exactly the same HardwareIds (exactly the same).

我在MSDN上找到了信息,所有输出似乎都记录在案,并且包含有关返回此工具的值的信息,但是它没有确切指定WMI类的属性,它只是说" Bios "和"系统":

I've found info on MSDN, all the output seems very documented and it contains info about the values that returns this tool, but it does not specify exactly what properties of the WMI classes are, it just says "Bios" and "System":

· ComputerHardwareIds概述

·指定硬件ID用于计算机

我很迷茫,找不到"Family","BIOS Vendor","Bios Major Release","Bios Minor Release"之类的值,并且不确定"SKU编号"在哪里指.

I'm very lost, I can't find any values such as "Family", "BIOS Vendor", "Bios Major Release", "Bios Minor Release" and I'm not sure where the "SKU Number" refers to.

我认为这些是WMI类,该工具从中获取所有数据的一部分以构成GUID:

I Think these are the WMI Classes where the tool obtains part of all the data to make the guid:

· Win32_BIOS类

· Win32_BaseBoard类

· Win32_ComputerSystem类

· Win32_ComputerSystemProduct类

请注意,文档中也说明了这一点:

Note that the documentation also says this:

然后使用SHA-1哈希将每个字符串转换为GUID 算法.

Each string is then converted into a GUID by using the SHA-1 hashing algorithm.


这是我尝试做的事情,但是我不确定我是否在某个概念或某些价值观上错了,它是不完整的,并且我在Guis上也遇到了问题(用注释行解释):


This is what I've tried to do, but I'm not sure whether i'm wrong with some concept or some values, it's incomplete and I also have problems with the Guis (explained with commentlines):

Private Function GetHardwareId() As Guid

    Dim HardwareId As String = String.Empty

    Dim BIOSVersion, BIOSVendor, BIOSMajorRelease, BIOSMinorRelease,
        SystemManufacturer, SystemFamily, SystemProductName, SKUNumber As String

    ' Get System Info.
    Using wmi As New Management.ManagementObjectSearcher("select * from Win32_ComputerSystem")

        Using SystemInfo As Management.ManagementObject = wmi.Get(0)

            SystemManufacturer = Convert.ToString(SystemInfo.Properties("Manufacturer").Value)
            SystemProductName = Convert.ToString(SystemInfo.Properties("Model").Value)
            SystemFamily = I don't know how to get it.
            SKUNumber = I don't know how to get it.

        End Using

    End Using

    ' Get BIOS Info.
    Using wmi As New Management.ManagementObjectSearcher("select * from Win32_BIOS")

        Using BIOSInfo As Management.ManagementObject = wmi.Get(0)

            BIOSVersion = Convert.ToString(BIOSInfo.Properties("SMBIOSBIOSVersion").Value) 
            BIOSVendor = I don't know how to get it.
            BIOSMajorRelease = I don't know how to get it.
            BIOSMinorRelease = I don't know how to get it.

        End Using

    End Using ' wmi

    HardwareId = BIOSVersion & BIOSVendor & BIOSMajorRelease & BIOSMinorRelease &
                 SystemManufacturer & SystemFamily & SystemProductName & SKUNumber

    ' Here I call other method to encode the resulting string to SHA1 Hash
    HardwareId = ConvertToSHA1(HardwareId)
    ' and then continue below...

    ' But this will not work, 
    ' it throws an exception about missing "-" chars in the SHA1 string.
    ' So Microsoft formats "manualy" the SHA1 string to add some "-"?
    Return Guid.Parse(HardwareId)

End Function

推荐答案

要生成相同的GUID,您需要从SMBIOS中获取值(通常使用GetSystemFirmwareTable),然后使用&"将它们连接起来字符确保字符串使用UTF-16编码.然后,您需要将类型5(SHA-1)UUID生成方案与

To generate the same GUIDs you need to get the values from SMBIOS (typically using GetSystemFirmwareTable), and then join them using the '&' char. Make sure the strings are encoded with UTF-16. You then need to use a type 5 (SHA-1) UUID generation scheme with 70ffd812-4c7f-4c7d-0000-000000000000 as the namespace.

这篇关于获取像Microsoft一样的硬件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆