Yashied Posted May 22, 2010 Share Posted May 22, 2010 (edited) This function generate a unique hardware identifier (ID) for your computer given the specified parameters ($UHID_... flags).$UHID_MB (0x00)Uses information about your motherboard. This flag is used by default regardless of whether specified or not.$UHID_BIOS (0x01)Uses information from BIOS.$UHID_CPU (0x02)Uses information about your processor(s). Note that $UHID_CPU flag reduces the function speed.$UHID_HDD (0x04)Uses information about the installed hard drives. Any change in the configuration disks will change ID returned by this function. Taken into account only non-removable disks with an ATA or SATA interfaces.The most optimum variant - $UHID_MB + $UHID_BIOS.The sequence of obtaining hardware information:Motherboard (IdentifyingNumber + Name + SKUNumber + UUID + Vendor + Version)+BIOS (IdentificationCode + Manufacturer + Name + SerialNumber + SMBIOSMajorVersion + SMBIOSMinorVersion)+Processors (CPU1 (Architecture + Family + Level + Manufacturer + Name + ProcessorId + Revision + Version) + CPU2 (...) + ...)+HDDs (HDD1 (SerialNumber) + HDD2 (...) + ...) expandcollapse popup#Include <Crypt.au3> #Include <WinAPI.au3> Global Const $UHID_MB = 0x00 Global Const $UHID_BIOS = 0x01 Global Const $UHID_CPU = 0x02 Global Const $UHID_HDD = 0x04 ConsoleWrite(_UniqueHardwaeIDv1() & @CR) ConsoleWrite(_UniqueHardwaeIDv1(BitOR($UHID_MB, $UHID_BIOS)) & @CR) ;ConsoleWrite(_UniqueHardwaeIDv1(BitOR($UHID_MB, $UHID_BIOS, $UHID_CPU)) & @CR) ;ConsoleWrite(_UniqueHardwaeIDv1(BitOR($UHID_MB, $UHID_BIOS, $UHID_CPU, $UHID_HDD)) & @CR) Func _UniqueHardwaeIDv1($iFlags = 0) Local $oService = ObjGet('winmgmts:\\.\root\cimv2') If Not IsObj($oService) Then Return SetError(1, 0, '') EndIf Local $tSPQ, $tSDD, $oItems, $hFile, $Hash, $Ret, $Str, $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, 0x01) Then $oItems = $oService.ExecQuery('SELECT * FROM Win32_BIOS') If Not IsObj($oItems) Then Return SetError(2, 0, '') EndIf $Str = '' For $Property In $oItems $Str &= $Property.IdentificationCode $Str &= $Property.Manufacturer $Str &= $Property.Name $Str &= $Property.SerialNumber $Str &= $Property.SMBIOSMajorVersion $Str &= $Property.SMBIOSMinorVersion ; $Str &= $Property.Version Next $Str = StringStripWS($Str, 8) If $Str Then $Result += 0x01 $Hw &= $Str EndIf EndIf If BitAND($iFlags, 0x02) Then $oItems = $oService.ExecQuery('SELECT * FROM Win32_Processor') If Not IsObj($oItems) Then Return SetError(2, 0, '') EndIf $Str = '' For $Property In $oItems $Str &= $Property.Architecture $Str &= $Property.Family $Str &= $Property.Level $Str &= $Property.Manufacturer $Str &= $Property.Name $Str &= $Property.ProcessorId $Str &= $Property.Revision $Str &= $Property.Version Next $Str = StringStripWS($Str, 8) If $Str Then $Result += 0x02 $Hw &= $Str EndIf EndIf If BitAND($iFlags, 0x04) Then $oItems = $oService.ExecQuery('SELECT * FROM Win32_PhysicalMedia') If Not IsObj($oItems) Then Return SetError(2, 0, '') EndIf $Str = '' $tSPQ = DllStructCreate('dword;dword;byte[4]') $tSDD = DllStructCreate('ulong;ulong;byte;byte;byte;byte;ulong;ulong;ulong;ulong;dword;ulong;byte[512]') For $Property In $oItems $hFile = _WinAPI_CreateFile($Property.Tag, 2, 0, 0) If Not $hFile Then ContinueLoop EndIf $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 (Not @error) And ($Ret[0]) And (Not DllStructGetData($tSDD, 5)) Then Switch DllStructGetData($tSDD, 11) Case 0x03, 0x0B ; ATA, SATA $Str &= $Property.SerialNumber EndSwitch EndIf _WinAPI_CloseHandle($hFile) Next $Str = StringStripWS($Str, 8) If $Str Then $Result += 0x04 $Hw &= $Str EndIf EndIf $Hash = _Crypt_HashData($Hw, $CALG_MD5) If @error Then Return SetError(4, 0, '') EndIf $Hash = StringTrimLeft($Hash, 2) 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 ;==>_UniqueHardwaeIDv1 Edited December 22, 2013 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
JohnOne Posted May 22, 2010 Share Posted May 22, 2010 Sounds ace, but would two computers with the same motherboard, cpu, hdd and bios not return the same ID? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Yashied Posted May 23, 2010 Author Share Posted May 23, 2010 (edited) Sounds ace, but would two computers with the same motherboard, cpu, hdd and bios not return the same ID?No. ID is unique for each computer. Meaning in this. Edited May 23, 2010 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now