如何获得驱动器的卷标和序列号.iss
; ISX 3.0.6.2
;
#ifdef Unicode
#define A "W"
#else
#define A "A"
#endif
[Setup]
AppName=DriveVolume
AppVerName=DriveVolume
Uninstallable=false
UpdateUninstallLogAppName=false
DisableDirPage=true
DisableProgramGroupPage=true
DefaultDirName={pf}\DriveVolume
DisableStartupPrompt=true
[_ISTool]
EnableISX=true
[Code]
function GetVolumeInformation(
lpRootPathName: String;
lpVolumeNameBuffer: String;
nVolumeNameSize: LongInt;
var lpVolumeSerialNumber: LongInt;
lpMaximumComponentLength: LongInt;
lpFileSystemFlags : LongInt;
lpFileSystemNameBuffer: String;
nFileSystemNameSize: LongInt ) : Integer;
external 'GetVolumeInformation{#A}@kernel32.dll stdcall';
{ // API declaration in C
BOOL GetVolumeInformation(
LPCTSTR lpRootPathName, // root directory
LPTSTR lpVolumeNameBuffer, // volume name buffer
DWORD nVolumeNameSize, // length of name buffer
LPDWORD lpVolumeSerialNumber, // volume serial number
LPDWORD lpMaximumComponentLength, // maximum file name length
LPDWORD lpFileSystemFlags, // file system options
LPTSTR lpFileSystemNameBuffer, // file system name buffer
DWORD nFileSystemNameSize // length of file system name buffer
);
}
function GetLastError( ) : Integer;
external '
GetLastError@kernel32.dll stdcall';
function InitializeSetup(): Boolean;
var srcdisk, volume: String;
ercode: Integer; sernum: LongInt;
begin
Result := true;
srcdisk := AddBackslash( ExtractFileDrive( ExpandConstant('{srcexe}') ) );
volume := StringOfChar( ' ', 16 );
if GetVolumeInformation( srcdisk, volume, 15, sernum, 0, 0, '', 0 ) = 0 then
begin
ercode := GetLastError();
MsgBox( SysErrorMessage( ercode ), mbError, MB_OK );
Result := false;
end
else begin
volume := CastIntegerToString( CastStringToInteger(volume) );
MsgBox( Format( '%s 的卷标是“%s”,序列号是 %s。', [srcdisk, volume, IntToStr(sernum)] )
, mbInformation, MB_OK );
end;
end;