Inno setup 搜索现有文件

use*_*935 3 inno-setup

如何搜索现有的 exe 文件,然后将该目录用于我的安装程序?

如果找不到 exe 文件,我希望用户浏览路径。如果 exe 文件安装在其他地方。

情况 1(最常见的情况):

默认目录是 c:\test\My program

这应该显示为“选择目标位置”页面上的路径。当用户按“下一步”时,应该有一个检查。确保默认目录存在 (c:\test\My program) 如果存在,用户应继续进入“准备安装”页面。

Senario 2(极少数情况):

默认目录是 c:\test\My program

这应该显示为“选择目标位置”页面上的路径。当用户按“下一步”时,应该有一个检查。确保默认目录存在 (c:\test\My program) 如果不存在,则应提示用户输入“My program”的路径。随后,用户应继续进入“准备安装”页面。然后我只相信用户选择了正确的路径

我怎样才能在 InnoSetup 中做到这一点?

小智 5

我已经对我的安装程序做了类似的事情。我做的第一件事是需要从程序中读取注册表值,如果该注册表值不存在,那么我选择该程序的默认目录。例如:

DefaultDirName={reg:HKLM\Software\Activision\Battlezone II,STInstallDir|reg:HKLM\Software\Activision\Battlezone II,Install121Dir|{pf32}\Battlezone II}
Run Code Online (Sandbox Code Playgroud)

现在,用户运行安装程序,它必须检查程序是否位于正确的文件夹中。它通过检查程序的可执行文件是否已经存在来实现这一点。我使用这段代码来做到这一点。

{ Below code warns end user if he tries to install into a folder that does not contain bzone.exe. Useful if user tries to install into addon or any non-BZ2 folder. }
function NextButtonClick(CurPageID: Integer): Boolean;
begin
  Log('NextButtonClick(' + IntToStr(CurPageID) + ') called');
  case CurPageID of
    wpSelectDir:
    if not FileExists(ExpandConstant('{app}\bzone.exe')) then begin
      MsgBox('Setup has detected that that this is not the main program folder of a Battlezone II install, and the created shortcuts to launch {#MyAppName} will not work.' #13#13 'You should probably go back and browse for a valid Battlezone II folder (and not any subfolders like addon).', mbError, MB_OK);
      end;
    wpReady:
  end;
  Result := True;
end;
Run Code Online (Sandbox Code Playgroud)

上面的代码只是检查目标可执行文件是否存在,如果不存在则警告用户,让他有机会返回并更改目录,但也可以继续安装。

另外,当您似乎正在为现有程序安装补丁或插件时,我建议您设置

DirExistsWarning=no
AppendDefaultDirName=false
Run Code Online (Sandbox Code Playgroud)

如果您不创建开始菜单条目,还可以选择阻止不必要的屏幕

DisableProgramGroupPage=yes
Run Code Online (Sandbox Code Playgroud)