C# / VB.NET硬件ID Generator(HWID / hardwareid )
一种API,可以有效利用Windows Management仪器Win32提供商根据主板,CDROM,BIOS,HDD,GPU和CPU的属性生成唯一的标识符(硬件ID)。此API的主要目的是允许软件根据其利用率保持锁定到一台PC(或多个)。
Windows根据WIN32提供商类(WMI)管理仪器
用法
C#语法用法:
hardwareid
hardwareid HWID = new hardwareid ();
//Generate Unique ID based upon hardware of current PC.
Console.WriteLine(HWID.Generate());
//Every time *Generate* is called it sets the *LastID* property.
Console.WriteLine(HWID.LastID)
//The internal *GetProperties* function uses a string array that follows the format { WMI_CLASS, Properties… }.
// Motherboard –> Parameters
// string[] MOTHERBOARD = { "Win32_BaseBoard", "Name", "Manufacturer", "Version" };
GetProperties(WMI_CLASSES.MOTHERBOARD);
private static string GetProcessorProperties()
{
return GetProperties(WMI_CLASSES.CPU);
}\”>
//Initialize instance of hardwareid hardwareid HWID = new hardwareid ( ) ; //Generate Unique ID based upon hardware of current PC. Console . WriteLine ( HWID . Generate ( ) ) ; //Every time *Generate* is called it sets the *LastID* property. Console . WriteLine ( HWID . LastID ) //The internal *GetProperties* function uses a string array that follows the format { WMI_CLASS, Properties... }. // Motherboard --> Parameters // string[] MOTHERBOARD = { \"Win32_BaseBoard\", \"Name\", \"Manufacturer\", \"Version\" }; GetProperties ( WMI_CLASSES . MOTHERBOARD ) ; private static string GetProcessorProperties ( ) { return GetProperties ( WMI_CLASSES . CPU ) ; }
VB.NET语法用法:
hardwareid
Dim HWID As New hardwareid ()
\’Generate Unique ID based upon hardware of current PC
Console.WriteLine(HWID.Generate())
\’Every time Generate is called LastID is set
Console.WriteLine(HWID.LastID)
\’The internal *GetProperties* function uses a string array that follows the format { WMI_CLASS, Properties… }.
\’ Motherboard –> Parameters
\’ Dim MOTHERBOARD As String() = New String() { "Win32_BaseBoard", "Name", "Manufacturer", "Version" }
Private Shared Function GetProcessorProperties()
Return GetProperties(WMI_CLASSES.CPU)
End Function\”>
\'Initialize instance of hardwareid Dim HWID As New hardwareid () \'Generate Unique ID based upon hardware of current PC Console.WriteLine(HWID.Generate()) \'Every time Generate is called LastID is set Console.WriteLine(HWID.LastID) \'The internal *GetProperties* function uses a string array that follows the format { WMI_CLASS, Properties... }. \' Motherboard --> Parameters \' Dim MOTHERBOARD As String() = New String() { \"Win32_BaseBoard\", \"Name\", \"Manufacturer\", \"Version\" } Private Shared Function GetProcessorProperties() Return GetProperties(WMI_CLASSES.CPU) End Function
从WMI类收集的每个属性都与SHA1一起使用,然后变成十六进制字符串。
//Output: A7EA-FB91-9995-84B7-E843-CCB4-4E81-51B9-2B3B-6587
更新
- 提高速度和效率。
- 找到了每个硬件的可靠属性。
待办事项
- 进一步优化WMI访问和查询生成
- 检查硬件是否存在,如果不存在,请尝试其他选项(预防运行时错误)
问题
- 假设存在cdromdrive。
执照
GNU通用公共许可证版本3,2007年6月29日
