Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Check that the disk is NTFS-formatted

62 views
Skip to first unread message

Otomatic

unread,
Mar 12, 2025, 6:25:33 AMMar 12
to innosetup
Hi,

Is there any way of checking, for example in the InitializeSetup() function, that the disk is NTFS formatted?
The application to be installed does not support Fat32 or exFAT.
Thank you for your help.

Bill Stewart

unread,
Mar 12, 2025, 11:55:59 AMMar 12
to innosetup
One way would be to use the GetVolumeInformation Windows API.

In the sample below, the GetFileSystemName calls the API and returns the file system name (e.g., 'NTFS') in the Name parameter.

[Setup]
AppName=TestCodeFileSystemName
ArchitecturesInstallIn64BitMode=x64compatible
AppVerName=TestCode
UsePreviousAppDir=false
DefaultDirName={commonpf}\TestCodeFileSystemName
Uninstallable=false
OutputDir=.
OutputBaseFilename=TestCodeFileSystemName
PrivilegesRequired=lowest

[Messages]
SetupAppTitle=TestCodeFileSystemName

[Code]
const
  MAX_PATH = 260;

function GetVolumeInformation(lpRootPathName: string;
  lpVolumeNameBuffer: string;
  nVolumeNameSize: DWORD;
  var lpVolumeSerialNumber: DWORD;
  var lpMaximumComponentLength: DWORD;
  var lpFileSystemFlags: DWORD;
  lpFileSystemNameBuffer: string;
  nFileSystemNameSize: DWORD): BOOL;
  external 'GetVolumeI...@kernel32.dll stdcall';

function GetFileSystemName(Drive: string; var Name: string): DWORD;
var
  FileSystemFlags: DWORD;
  VolumeSerialNumber: DWORD;
  MaximumComponentLength: DWORD;
begin
  result := 0;  // ERROR_SUCCESS
  Drive := AddBackslash(Drive);
  SetLength(Name, MAX_PATH);
  if GetVolumeInformation(Drive,  // LPCWSTR lpRootPathName
    '',                           // LPWSTR  lpVolumeNameBuffer
    0,                            // DWORD   nVolumeNameSize
    VolumeSerialNumber,           // LPDWORD lpVolumeSerialNumber
    MaximumComponentLength,       // LPDWORD lpMaximumComponentLength
    FileSystemFlags,              // LPDWORD lpFileSystemFlags
    Name,                         // LPWSTR  lpFileSystemNameBuffer
    Length(Name)) then            // DWORD   nFileSystemNameSize
  begin
    SetLength(Name, Pos(#0, Name) - 1);
  end
  else
    result := DLLGetLastError();
end;

procedure Test();
var
  ErrorCode: DWORD;
  FileSystemName: string;
begin
  ErrorCode := GetFileSystemName('C:', FileSystemName);
  if ErrorCode = 0 then
    MsgBox(FileSystemName, mbInformation, MB_OK)
  else
    MsgBox('Error ' + IntToStr(ErrorCode), mbError, MB_OK);
end;

function InitializeSetup(): Boolean;
begin
  result := false;
  Test();
end;

Bill Stewart

unread,
Mar 12, 2025, 1:56:16 PMMar 12
to innosetup
On Wednesday, March 12, 2025 at 9:55:59 AM UTC-6 Bill Stewart wrote:

  external 'GetVolumeI...<at>kernel32.dll stdcall';

GetVolumeI...<at>kernel32.dll should be GetVolumeInformationW<at>kernel32.dll

(and replace <at> with the @ character)

(Google groups being 'helpful' in removing what it thinks are email addresses from posts)

Bill

Otomatic

unread,
Mar 13, 2025, 3:41:17 AMMar 13
to innosetup
Thank you very much. It works perfectly.
Reply all
Reply to author
Forward
0 new messages