 .)
 .)je fais partager ce fameux le voici ci dessous
► Afficher le texte
Code : Tout sélectionner
#include <WinApi.au3>
Global Const $UHID_MB = 0x0000
Global Const $UHID_BIOS = 0x0001
Global Const $UHID_CPU = 0x0002
Global Const $UHID_HDD = 0x0004
Global Const $UHID_All = BitOR($UHID_MB, $UHID_BIOS, $UHID_CPU, $UHID_HDD)
$H1 = 'Hardware1: ' & _WinAPI_UniqueHardwareID() & @CRLF
$H2 = 'Hardware2: ' & _WinAPI_UniqueHardwareID(BitOR($UHID_MB, $UHID_BIOS)) & @CRLF
$H3 = 'Hardware3: ' & _WinAPI_UniqueHardwareID(BitOR($UHID_MB, $UHID_BIOS, $UHID_CPU)) & @CRLF
$H4 = 'Hardware4: ' & _WinAPI_UniqueHardwareID($UHID_All) & @CRLF
MsgBox(64,"HWID",$H1&$H2&$H3&$H4)
Func _WinAPI_UniqueHardwareID($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 * 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 * 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 * 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 * 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_UniqueHardwareID
Func __MD5($sData)
    Local $Ret, $hProv, $hHash, $tData, $Error = 1
    $hProv = DllCall('advapi32.dll', 'int', 'CryptAcquireContextW', 'ptr*', 0, 'ptr', 0, 'ptr', 0, 'dword', 3, 'dword', 0xF0000000)
    If (@error) Or (Not $hProv[0]) Then
        Return ''
    EndIf
    Do
        $hHash = DllCall('advapi32.dll', 'int', 'CryptCreateHash', 'ptr', $hProv[1], 'uint', 0x00008003, 'ptr', 0, 'dword', 0, 'ptr*', 0)
        If (@error) Or (Not $hProv[0]) Then
            $hHash = 0
            ExitLoop
        EndIf
        $hHash = $hHash[5]
        $tData = DllStructCreate('byte[' & BinaryLen($sData) & ']')
        DllStructSetData($tData, 1, $sData)
        $Ret = DllCall('advapi32.dll', 'int', 'CryptHashData', 'ptr', $hHash, 'ptr', DllStructGetPtr($tData), 'dword', DllStructGetSize($tData), 'dword', 1)
        If (@error) Or (Not $Ret[0]) Then
            ExitLoop
        EndIf
        $tData = DllStructCreate('byte[16]')
        $Ret = DllCall('advapi32.dll', 'int', 'CryptGetHashParam', 'ptr', $hHash, 'dword', 2, 'ptr', DllStructGetPtr($tData), 'dword*', 16, 'dword', 0)
        If (@error) Or (Not $Ret[0]) Then
            ExitLoop
        EndIf
        $Error = 0
    Until 1
    If $hHash Then
        DllCall('advapi32.dll', 'int', 'CryptDestroyHash', 'ptr', $hHash)
    EndIf
    If $Error Then
        Return ''
    EndIf
    Return StringTrimLeft(DllStructGetData($tData, 1), 2)
EndFunc   ;==>__MD5
Func _WinAPI_GetDriveBusType($sDrive)
    Local $hFile = _WinAPI_CreateFileEx('\\.\' & $sDrive, 3, 0, 0)
    If Not $hFile Then
        Return SetError(1, 0, -1)
    EndIf
    Local $tSPQ = DllStructCreate('ulong PropertyId;ulong QueryType;byte AdditionalParameters[4]')
    Local $tSDD = DllStructCreate('ulong Version;ulong Size;byte DeviceType;byte DeviceTypeModifier;byte RemovableMedia;byte CommandQueueing;ulong VendorIdOffset;ulong ProductIdOffset;ulong ProductRevisionOffset;ulong SerialNumberOffset;ulong BusType;ulong RawPropertiesLength;byte RawDeviceProperties[1]')
    DllStructSetData($tSPQ, 'PropertyId', 0)
    DllStructSetData($tSPQ, 'QueryType', 0)
    Local $Ret = DllCall('kernel32.dll', 'int', 'DeviceIoControl', 'ptr', $hFile, 'dword', 0x002D1400, 'ptr', DllStructGetPtr($tSPQ), 'dword', DllStructGetSize($tSPQ), 'ptr', DllStructGetPtr($tSDD), 'dword', DllStructGetSize($tSDD), 'dword*', 0, 'ptr', 0)
    If (@error) Or (Not $Ret[0]) Then
        $Ret = 0
    EndIf
    _WinAPI_CloseHandle($hFile)
    If Not IsArray($Ret) Then
        Return SetError(2, 0, -1)
    EndIf
    Return DllStructGetData($tSDD, 'BusType')
EndFunc   ;==>_WinAPI_GetDriveBusType
Func _WinAPI_CreateFileEx($sFile, $iCreation, $iAccess, $iShare, $iFlagsAndAttributes = 0, $tSecurity = 0, $hTemplate = 0)
    Local $Ret = DllCall('kernel32.dll', 'ptr', 'CreateFileW', 'wstr', $sFile, 'dword', $iAccess, 'dword', $iShare, 'ptr', DllStructGetPtr($tSecurity), 'dword', $iCreation, 'dword', $iFlagsAndAttributes, 'ptr', $hTemplate)
    If (@error) Or ($Ret[0] = Ptr(-1)) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[0]
EndFunc   ;==>_WinAPI_CreateFileEx



