Get Disk Volume Serial Number: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
ChrisMorgan (talk | contribs) (Added a macro for easier usage) |
ChrisMorgan (talk | contribs) m (Quoted %08X in IntFmt) |
||
Line 18: | Line 18: | ||
To then convert this serial number into hexadecimal: | To then convert this serial number into hexadecimal: | ||
<highlight-nsis> | <highlight-nsis> | ||
IntFmt $0 %08X $0 | IntFmt $0 "%08X" $0 | ||
</highlight-nsis> | </highlight-nsis> | ||
Line 36: | Line 36: | ||
!macro GetDiskVolumeSerialNumberHex _SERIAL _DRIVE | !macro GetDiskVolumeSerialNumberHex _SERIAL _DRIVE | ||
${GetDiskVolumeSerialNumber} ${_SERIAL} ${_DRIVE} | ${GetDiskVolumeSerialNumber} ${_SERIAL} ${_DRIVE} | ||
IntFmt ${_SERIAL} %08X ${_SERIAL} | IntFmt ${_SERIAL} "%08X" ${_SERIAL} | ||
!macroend | !macroend | ||
!define GetDiskVolumeSerialNumberHex "!insertmacro GetDiskVolumeSerialNumberHex" | !define GetDiskVolumeSerialNumberHex "!insertmacro GetDiskVolumeSerialNumberHex" |
Revision as of 23:10, 10 November 2009
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 ; Find the serial number ${GetDiskVolumeSerialNumber} $1 $0\ ; Or find it as hex ${GetDiskVolumeSerialNumberHex} $1 $0\