gpt4 book ai didi

windows - Inno Setup - 检查目标中是否存在文件,否则不中止安装

转载 作者:可可西里 更新时间:2023-11-01 12:31:04 24 4
gpt4 key购买 nike

我需要我的安装程序检查目标位置是否存在文件,如果不存在,则安装中止。我的项目是更新补丁,所以如果应用程序的主 exe 不在目标位置,我希望安装程序避免安装更新文件。我该怎么做?

谁能给出一个通过 Windows 注册表检查文件版本的代码示例?

[Files]
Source C:\filename.exe; DestDir {app}; Flags: ignoreversion; BeforeInstall: CheckForFile;

[code]

procedure CheckForFile(): Boolean;
begin
if (FileExists('c:\somefile.exe')) then
begin
MsgBox('File exists, install continues', mbInformation, MB_OK);
Result := True;
end
else
begin
MsgBox('File does not exist, install stops', mbCriticalError, MB_OK);
Result := False;
end;
end;

最佳答案

在用户选择正确的文件夹之前不要让他们继续。

function NextButtonClick(PageId: Integer): Boolean;
begin
Result := True;
if (PageId = wpSelectDir) and not FileExists(ExpandConstant('{app}\yourapp.exe')) then begin
MsgBox('YourApp does not seem to be installed in that folder. Please select the correct folder.', mbError, MB_OK);
Result := False;
exit;
end;
end;

当然,尝试自动为他们选择正确的文件夹也是一个好主意,例如。通过从注册表中检索正确的位置。

关于windows - Inno Setup - 检查目标中是否存在文件,否则不中止安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12951327/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com