Get Disk Volume Serial Number
From NSIS Wiki
Jump to navigationJump to search
Author: b_avery@yahoo.com (talk, contrib) |
Description
Do you need to find out the Disc Serial Number, well here you go, $0 - Drive to check returns the Disc Serial Number
; $0 - Drive to check returns the Disc Serial Number Function GetDiskVolumeSerialNumber !define GetVolumeInformation "Kernel32::GetVolumeInformation(t,t,i,*i,*i,*i,t,i) i" System::Call '${GetVolumeInformation}("$0",,${NSIS_MAX_STRLEN},.r0,,,,${NSIS_MAX_STRLEN})' FunctionEnd ;GetDiskVolumeSerialNumber
This has been created as a result of:
http://forums.winamp.com/showthread.php?postid=1320397#post1320397
To then convert this serial number into hexadecimal:
IntFmt $0 "%08X" $0
Macro
This macro was created from the code above by Chris Morgan.
!define _GetVolumeInformationSysCall "Kernel32::GetVolumeInformation(t,t,i,*i,*i,*i,t,i) i" !macro GetDiskVolumeSerialNumber _SERIAL _DRIVE Push $0 System::Call '${_GetVolumeInformationSysCall}("${_DRIVE}",,${NSIS_MAX_STRLEN},.r0,,,,${NSIS_MAX_STRLEN})' Exch $0 Pop ${_SERIAL} !macroend !define GetDiskVolumeSerialNumber "!insertmacro GetDiskVolumeSerialNumber" !macro GetDiskVolumeSerialNumberHex _SERIAL _DRIVE ${GetDiskVolumeSerialNumber} ${_SERIAL} ${_DRIVE} IntFmt ${_SERIAL} "%08X" ${_SERIAL} !macroend !define GetDiskVolumeSerialNumberHex "!insertmacro GetDiskVolumeSerialNumberHex"
Example usage, to find the serial number of the system drive:
ReadEnvStr $0 SystemDrive StrCpy $0 "$0\" ; Find the serial number ${GetDiskVolumeSerialNumber} $1 $0 ; Or find it as hex ${GetDiskVolumeSerialNumberHex} $1 $0