您可以通过该部分分配DefaultDirName
指令的值。[Code]
例如,以下伪脚本显示了如何在注册表中查询两个字符串值并将找到的第一个返回给DefaultDirName
指令。如果没有找到查询的注册表值,则返回默认常量值:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={code:GetDirName}
[Code]
function GetDirName(Value: string): string;
var
InstallPath: string;
begin
// initialize default path, which will be returned when the following registry
// key queries fail due to missing keys or for some different reason
Result := '{pf}\Default Dir Name';
// query the first registry value; if this succeeds, return the obtained value
if RegQueryStringValue(HKLM, 'Software\Vendor\Application', 'First Key', InstallPath) then
Result := InstallPath
// otherwise the first registry key query failed, so...
else
// query the second registry value; if it succeeds, return the obtained value
if RegQueryStringValue(HKLM, 'Software\Vendor\Application', 'Second Key', InstallPath) then
Result := InstallPath;
end;