Since InnoSetup
does not support pointers, you will need to create an external library to call GetVolumeInformation
. The following code examples should work for all combinations of Delphi and InnoSetup (in terms of Unicode support).
Here is the Delphi library code:
library VolumeInformation; uses Types, Classes, SysUtils, Windows; var SerialNumber: AnsiString; function GetVolumeSerial(Drive: PAnsiChar): PAnsiChar; stdcall; var FileSystemFlags: DWORD; VolumeSerialNumber: DWORD; MaximumComponentLength: DWORD; begin SerialNumber := ''; GetVolumeInformationA(Drive, nil, 0, @VolumeSerialNumber, MaximumComponentLength, FileSystemFlags, nil, 0); SerialNumber := IntToHex(HiWord(VolumeSerialNumber), 4) + ' - ' + IntToHex(LoWord(VolumeSerialNumber), 4); Result := PAnsiChar(SerialNumber); end; exports GetVolumeSerial; end.
And here is the InnoSetup code:
[Files] Source: "VolumeInformation.dll"; Flags: dontcopy [Code] function GetVolumeSerial(Drive: PAnsiChar): PAnsiChar; external ' GetVolumeSerial@files :VolumeInformation.dll stdcall setuponly'; procedure ButtonOnClick(Sender: TObject); var S: string; begin S := GetVolumeSerial('c:\'); MsgBox(S, mbInformation, mb_Ok); end;
TLama source share