Search code examples
inno-setuppascalscript

How to check partition type in Inno Setup?


I have task in which I need to perform installer, who will check the partition type (eg. FAT32, NTFS), and will not allow the installation if the partition does not support file larger than 4GB.

To be honest I have no idea how I can do this. Whether you would have any idea how to go about it? Maybe some piece of code that performs verification of the type of partition?

I would be grateful for any idea to perform this task.


Solution

  • There is an answer for your question here.

    This simple example checks the partition type on wpSelectDir Page and if NTFS is detected on the destination partition it allows to carry on the installation process.

    It was written for older version of Inno Setup, so some changes are required (e.g. to MsgBox's Format2) If you are using Unicode Inno you would have to change it a little though.

    Below you will find script updated for the latest version of Unicode Inno Setup.

    [Setup]
    AppName=Filesystem
    AppVerName=Filesystem
    Uninstallable=false
    UpdateUninstallLogAppName=false
    DisableDirPage=false
    DisableProgramGroupPage=true
    DefaultDirName={pf}\Filesystem
    DisableStartupPrompt=true
    
    [Code]
    #ifdef UNICODE
      #define AW "W"
    #else
      #define AW "A"
    #endif
     
    const
      MAX_PATH = 260;
    
    function GetVolumeInformation(lpRootPathName: string; lpVolumeNameBuffer: string;
      nVolumeNameSize: DWORD; out lpVolumeSerialNumber: DWORD;
      out lpMaximumComponentLength: DWORD; out lpFileSystemFlags: DWORD;
      lpFileSystemNameBuffer: string; nFileSystemNameSize: DWORD): BOOL;
      external 'GetVolumeInformation{#AW}@kernel32.dll stdcall';
    
    function NextButtonClick(CurPage: Integer): Boolean;
    var srcdisk : String;
        sernum, dummy1, dummy2: DWORD;
        fstype: String;
    begin
      Result := true;
      if CurPage = wpSelectDir then
      begin
        srcdisk := AddBackslash(ExtractFileDrive(WizardDirValue));
        fstype := StringOfChar(#0, MAX_PATH + 1);
        if not GetVolumeInformation(
                 srcdisk, '', 0, sernum, dummy1, dummy2, fstype, Length(fstype)) then
        begin
          MsgBox(SysErrorMessage(DLLGetLastError), mbError, mb_Ok);
          Result := false;
        end else
        begin
          fstype := Uppercase(Trim(fstype));
          MsgBox (Format('Volume %s has filesystem type (%s)', [
            srcdisk, fstype]), mbInformation, MB_OK);
          // Only carry on if the file system is NTFS.
          Result := (fstype = 'NTFS');
        end;
      end;
    end;