获取 HWID(处理器 ID、主板序列号) [英] Get HWID (processorID, MotherboardSerialNumber)

查看:262
本文介绍了获取 HWID(处理器 ID、主板序列号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个项目,但我的问题是,当我尝试获取完全为空的主板序列号时.

I am working on a project, and my problem, when I try to get the motherboard serial number its totally empty.

Dim HWID As String = String.Empty
Dim mcl As New ManagementClass("win32_processor")
Dim MOBC As ManagementObjectCollection = mcl.GetInstances()

For Each mob As ManagementObject In MOBC
    If HWID = "" Then
        HWID = mob.Properties("processorID").Value.ToString()
        Exit For
    End If

Next
Dim mboardstr As String = Nothing
 Dim mbs As ManagementObjectSearcher = New ManagementObjectSearcher("Select * From Win32_BaseBoard")
For Each mo As ManagementObject In mbs.Get
    mboardstr = mboardstr + mo("SerialNumber").ToString
Next
MsgBox(mboardstr)

HWID - 处理器 ID 没问题,但我也真的想要主板序列号,因为之后我将它放入一个字符串中并将其发布到远程主机.

HWID - processorid is okey, but I really want the motherboard serial too, because after that I put it into one string and post it to the remote host.

为什么我没有序列号"?谢谢!

Why I dont have "serialnumber"? Thanks!

推荐答案

并非所有数据都适用于所有系统.在这种情况下,您要查找的文本之前可能有其他数据,这会阻止获取字符串.WMI 很慢,所以你可以通过查询你想要的东西来加速它(vs SELECT *).

Not all data is available on all systems. In this case, there might be other data ahead of the text you are looking for which prevents the string from being fetched. WMI is pretty slow, so you can speed it up by just querying for what you are after (vs SELECT *).

其中一些东西应该被处理以释放资源,你应该在使用它们之前检查一些东西以确保它们不为空:

Some of those things should be disposed of to release resources and you should check some of the things to make sure they are not null before using them:

Dim mboardstr As String = ""
Dim query As String = "Select SerialNumber From Win32_BaseBoard"

Using mbs As ManagementObjectSearcher = New ManagementObjectSearcher(query)
    For Each mo As ManagementObject In mbs.Get
        For Each pd As PropertyData In mo.Properties
            ' should be only one
            If pd.Name = "SerialNumber" Then
                ' value is object, test for Nothing
                If pd.Value IsNot Nothing Then
                    mboardstr = pd.Value.ToString
                End If
                Exit For
            End If
        Next
    Next
End Using

您还可以设置断点,并检查 pd.Value 以查看是否有前导空值或其他不可打印的控制字符(很常见).你所追求的可能在他们背后".

You could also set a breakpoint, and examine pd.Value to see if there are leading nuls or other unprintable control characters (quite common). What you are after might be "behind" them.

这篇关于获取 HWID(处理器 ID、主板序列号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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