GetVolumeInformation ()

From ISXKB

Jump to: navigation, search

This article shows how to use the Windows API function GetVolumeInformation with Inno Setup.

Declaration

The following declaration is required in a [Code] section:

function GetVolumeInformation(
  lpRootPathName: PChar;
  lpVolumeNameBuffer: PChar;
  nVolumeNameSize: LongInt;
  var lpVolumeSerialNumber: LongInt;
  lpMaximumComponentLength: LongInt;
  lpFileSystemFlags : LongInt;
  lpFileSystemNameBuffer: PChar;
  nFileSystemNameSize: LongInt) : Integer;
external 'GetVolumeInformationA@kernel32.dll';

GetVolumeInformation () at MSDN

Example

The example shows how to only allow the installation on NTFS file systems.

[Setup]
AppName=Filesystem
AppVerName=Filesystem
Uninstallable=false
UpdateUninstallLogAppName=false
DisableDirPage=false
DisableProgramGroupPage=true
DefaultDirName={pf}\Filesystem
DisableStartupPrompt=true

[Code]
function GetVolumeInformation(
  lpRootPathName: PChar;
  lpVolumeNameBuffer: PChar;
  nVolumeNameSize: LongInt;
  var lpVolumeSerialNumber: LongInt;
  lpMaximumComponentLength: LongInt;
  lpFileSystemFlags : LongInt;
  lpFileSystemNameBuffer: PChar;
  nFileSystemNameSize: LongInt) : Integer;
 external 'GetVolumeInformationA@kernel32.dll';

function GetLastError () : Integer;
 external 'GetLastError@kernel32.dll';


function NextButtonClick(CurPage: Integer): Boolean;
var srcdisk : String;
    ercode: Integer; sernum: LongInt;
    fstype: String;
begin
  Result := true;
  if CurPage = wpSelectDir then
  begin
    srcdisk := AddBackslash (ExtractFileDrive (WizardDirValue ));
    fstype := StringOfChar (' ', 12);
    if GetVolumeInformation (srcdisk, '', 0, sernum, 0, 0, fstype, 11) = 0 then
    begin
      ercode := GetLastError ();
      MsgBox (SysErrorMessage (ercode), mbError, MB_OK);
      Result := false;
    end else
    begin
      fstype := CastIntegerToString (CastStringToInteger (fstype));
      MsgBox (Format2 ('Volume %s has filesystem type (%s)', srcdisk, fstype), mbInformation, MB_OK);
      // Only carry on if the file system is NTFS.
      Result := (Uppercase (Trim (fstype)) = 'NTFS');
    end;
  end;
end;
Personal tools
Ads: