如何在 Inno Setup 中检查分区类型?
How to check partition type in Inno Setup?
我有任务需要执行安装程序,安装程序会检查分区类型(例如 FAT32、NTFS),如果分区不支持大于 4GB 的文件,则不允许安装。
老实说,我不知道该怎么做。您是否知道如何去做?也许是一些执行分区类型验证的代码?
对于执行此任务的任何想法,我将不胜感激。
您的问题有答案here。
此简单示例检查 wpSelectDir
页面上的分区类型,如果在目标分区上检测到 NTFS
,则允许继续安装过程。
它是为旧版本的 Inno Setup 编写的,因此需要进行一些更改(例如 MsgBox
的 Format2
)
如果您使用的是 Unicode Inno,则必须稍作更改。
您将在下面找到针对最新版本的 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;
我有任务需要执行安装程序,安装程序会检查分区类型(例如 FAT32、NTFS),如果分区不支持大于 4GB 的文件,则不允许安装。
老实说,我不知道该怎么做。您是否知道如何去做?也许是一些执行分区类型验证的代码?
对于执行此任务的任何想法,我将不胜感激。
您的问题有答案here。
此简单示例检查 wpSelectDir
页面上的分区类型,如果在目标分区上检测到 NTFS
,则允许继续安装过程。
它是为旧版本的 Inno Setup 编写的,因此需要进行一些更改(例如 MsgBox
的 Format2
)
如果您使用的是 Unicode Inno,则必须稍作更改。
您将在下面找到针对最新版本的 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;