#include <WinAPIEx.au3>
#Include <APIConstants.au3>
Opt('MustDeclareVars', 1)
Global $iTimer, $iTimeEx, $iTime, $sUniq, $sUniqEx
$iTimer = TimerInit()
$sUniqEx = _WinAPI_UniqueHardwareIDEx($UHID_All)
$iTimeEx = TimerDiff($iTimer)
ConsoleWrite('$sUniqEx: ' & $sUniqEx & @LF)
ConsoleWrite('$iTimeEx: ' & Round($iTimeEx, 2) & ' ms' & @LF)
$iTimer = TimerInit()
$sUniq = _WinAPI_UniqueHardwareID($UHID_All)
$iTime = TimerDiff($iTimer)
ConsoleWrite('$sUniq: ' & $sUniq & @LF)
ConsoleWrite('$iTime: ' & Round($iTime, 2) & ' ms' & @LF)
ConsoleWrite('$sUniqEx = $sUniq -> ' & ($sUniqEx = $sUniq) & @LF)
ConsoleWrite('$iTimer / $iTimerEx = ' & Round($iTime / $iTimeEx, 2) & @LF)
Func _WinAPI_UniqueHardwareIDEx($iFlags = 0)
Local $oService = ObjGet('winmgmts:\\.\root\cimv2')
If Not IsObj($oService) Then
Return SetError(1, 0, '')
EndIf
Local $oItems, $Hash, $Text, $Hw = '', $Result = 0
$oItems = $oService.ExecQuery('SELECT IdentifyingNumber,Name,SKUNumber,UUID,Vendor,Version FROM Win32_ComputerSystemProduct')
If Not IsObj($oItems) Then
Return SetError(2, 0, '')
EndIf
For $Property In $oItems
$Hw &= $Property.IdentifyingNumber
$Hw &= $Property.Name
$Hw &= $Property.SKUNumber
$Hw &= $Property.UUID
$Hw &= $Property.Vendor
$Hw &= $Property.Version
Next
$Hw = StringStripWS($Hw, 8)
If Not $Hw Then
Return SetError(3, 0, '')
EndIf
If BitAND($iFlags, 0x0001) Then
$oItems = $oService.ExecQuery('SELECT IdentificationCode,Manufacturer,Name,SerialNumber,SMBIOSMajorVersion,SMBIOSMinorVersion FROM Win32_BIOS')
If Not IsObj($oItems) Then
Return SetError(2, 0, '')
EndIf
$Text = ''
For $Property In $oItems
$Text &= $Property.IdentificationCode
$Text &= $Property.Manufacturer
$Text &= $Property.Name
$Text &= $Property.SerialNumber
$Text &= $Property.SMBIOSMajorVersion
$Text &= $Property.SMBIOSMinorVersion
; $Text &= $Property.Version
Next
$Text = StringStripWS($Text, 8)
If $Text Then
$Result += 0x0001
$Hw &= $Text
EndIf
EndIf
If BitAND($iFlags, 0x0002) Then
$oItems = $oService.ExecQuery('SELECT Architecture,Family,Level,Manufacturer,Name,ProcessorId,Revision,Version FROM Win32_Processor')
If Not IsObj($oItems) Then
Return SetError(2, 0, '')
EndIf
$Text = ''
For $Property In $oItems
$Text &= $Property.Architecture
$Text &= $Property.Family
$Text &= $Property.Level
$Text &= $Property.Manufacturer
$Text &= $Property.Name
$Text &= $Property.ProcessorId
$Text &= $Property.Revision
$Text &= $Property.Version
Next
$Text = StringStripWS($Text, 8)
If $Text Then
$Result += 0x0002
$Hw &= $Text
EndIf
EndIf
If BitAND($iFlags, 0x0004) Then
$oItems = $oService.ExecQuery('SELECT SerialNumber,Tag FROM Win32_PhysicalMedia')
If Not IsObj($oItems) Then
Return SetError(2, 0, '')
EndIf
$Text = ''
For $Property In $oItems
Switch _WinAPI_GetDriveBusType($Property.Tag)
Case 0x03, 0x0B
$Text &= $Property.SerialNumber
Case Else
EndSwitch
Next
$Text = StringStripWS($Text, 8)
If $Text Then
$Result += 0x0004
$Hw &= $Text
EndIf
EndIf
$Hash = __MD5($Hw)
If Not $Hash Then
Return SetError(4, 0, '')
EndIf
Return SetError(0, $Result, '{' & StringMid($Hash, 1, 8) & '-' & StringMid($Hash, 9, 4) & '-' & StringMid($Hash, 13, 4) & '-' & StringMid($Hash, 17, 4) & '-' & StringMid($Hash, 21, 12) & '}')
EndFunc ;==>_WinAPI_UniqueHardwareIDEx