我已经用我的安装程序做了类似的事情。我要做的第一件事是需要从程序中读取注册表值,如果该注册表值不存在,那么我选择该程序的默认目录。例如:
DefaultDirName={reg:HKLM\Software\Activision\Battlezone II,STInstallDir|reg:HKLM\Software\Activision\Battlezone II,Install121Dir|{pf32}\Battlezone II}
现在,用户运行安装程序,它必须检查程序是否在正确的文件夹中。它通过检查程序的可执行文件是否已经存在来做到这一点。我使用这段代码来做到这一点。
{ 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;
上面的代码只是检查目标可执行文件是否存在,如果不存在则警告用户,让他有机会返回并更改目录,但也可以继续安装。
此外,由于您似乎正在为现有程序安装补丁或插件,我建议您设置
DirExistsWarning=no
AppendDefaultDirName=false
如果您不创建开始菜单条目,还可以选择防止出现不必要的屏幕
DisableProgramGroupPage=yes