gpt4 book ai didi

vb.net - 从 PC 获取唯一的硬件 ID

转载 作者:行者123 更新时间:2023-12-05 08:23:28 25 4
gpt4 key购买 nike

我尝试从我的 PC 获取硬盘和主板序列号。它在 Windows 7 及更高版本中运行良好

但 CMD 中的相同代码不适用于 Windows XP。它显示要填写的 O.E.M 或返回任何内容

wmic diskdrive get name,serialnumber,model // This is cmd to get serial num

在 Windows XP 中它返回序列号错误

wmic baseboard get product,Manufacturer,version,serialnumber // This is cmd to get MotherBoard serialnumber

在 Windows XP 和 Win 8 中,它返回序列号错误,如“To be filled by O.E.M

正在寻找 Best Pc Unique Id ,它可以为任何操作系统返回 id 或序列号,并且应该是唯一的..

请帮帮我

谢谢。

最佳答案

我在网上找到了一个小项目:

  • 处理器 ID
  • 主板ID
  • 卷序列号
  • Mac 地址 ID

然后他们通过 MD5 对它进行哈希处理,但它现在已经贬值了,所以最好的办法是做同样的事情并通过 Sha512

对其进行哈希处理

如果没有自动完成,您首先需要导入和引用:

Imports System.Management
Imports System.Security.Cryptography
Imports System.Text

然后函数获取HWID(HardwareID)

Public Function Get_HWID() As String
'Information Handler
Dim hw As New clsComputerInfo
'Decalre variables
Dim hdd, cpu, mb, mac As String
'Get all the values
cpu = hw.GetProcessorId()
hdd = hw.GetVolumeSerial("C")
mb = hw.GetMotherBoardID()
mac = hw.GetMACAddress()
'Generate the hash
Dim hwid As String = GenerateSHA512String(cpu & hdd & mb & mac)
Return hwid
End Function

生成Hash的函数:

Public Shared Function GenerateSHA512String(ByVal inputString) As String
Dim sha512 As SHA512 = SHA512Managed.Create()
Dim bytes As Byte() = Encoding.UTF8.GetBytes(inputString)
Dim hash As Byte() = sha512.ComputeHash(bytes)
Dim stringBuilder As New StringBuilder()
For i As Integer = 0 To hash.Length - 1
stringBuilder.Append(hash(i).ToString("X2"))
Next
Return stringBuilder.ToString()
End Function

最后类获取信息:

Public Class clsComputerInfo
Friend Function GetProcessorId() As String
Dim strProcessorId As String = String.Empty
Dim query As New SelectQuery("Win32_processor")
Dim search As New ManagementObjectSearcher(query)
Dim info As ManagementObject
For Each info In search.Get()
strProcessorId = info("processorId").ToString()
Next
Return strProcessorId
End Function
Friend Function GetMACAddress() As String
Dim mc As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
Dim MACAddress As String = String.Empty
For Each mo As ManagementObject In moc
If (MACAddress.Equals(String.Empty)) Then
If CBool(mo("IPEnabled")) Then MACAddress = mo("MacAddress").ToString()
mo.Dispose()
End If
MACAddress = MACAddress.Replace(":", String.Empty)
Next
Return MACAddress
End Function
Friend Function GetVolumeSerial(Optional ByVal strDriveLetter As String = "C") As String
Dim disk As ManagementObject = New ManagementObject(String.Format("win32_logicaldisk.deviceid=""{0}:""", strDriveLetter))
disk.Get()
Return disk("VolumeSerialNumber").ToString()
End Function
Friend Function GetMotherBoardID() As String
Dim strMotherBoardID As String = String.Empty
Dim query As New SelectQuery("Win32_BaseBoard")
Dim search As New ManagementObjectSearcher(query)
Dim info As ManagementObject
For Each info In search.Get()
strMotherBoardID = info("SerialNumber").ToString()
Next
Return strMotherBoardID
End Function
End Class

我查看了 this project 的代码

希望这对您有所帮助,请记得添加对管理的引用

更多信息:

用于 HWID 的最常见 ID 是:CPU ID基于 MAC 地址的硬件 ID硬盘序列号

不建议将 HWID 作为许可系统,因为如果用户更改计算机或格式化驱动器等,它不准确且不实用。更建议使用证书系统或更复杂的身份验证。

关于vb.net - 从 PC 获取唯一的硬件 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43408464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com