{drive: Path } 只是获取路径中的磁盘盘符,如果你要获取原程序的安装目录的父目录,这个命令是没有用的,需要自己写个截取子字符串函数。你试试以下脚本:
[Setup]
AppName=Adobe Premiere 6.5 Patch
AppVerName=Adobe Premiere 4.0.0.58版本
AppPublisher=Adobe Premiere 6.5
;DefaultDirName={reg:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Premiere 6.5,InstallLocation}
;默认安装目录改为从代码段获取,以便在注册表值为空时可以做更多的处理,
'如给出提示并终止安装,或使用默认目录(示例脚本为默认目录)
DefaultDirName={code:MyConst}
OutputDir=C:\Users\Public\Desktop
OutputBaseFilename=Patch
SolidCompression=yes
Compression=lzma/ultra64
//此压缩为7z极限压缩算法
DisableDirPage=no
DisableProgramGroupPage=yes
DirExistsWarning=no
Uninstallable=no
WizardImageFile=C:\Users\Administrator\Desktop\Office2007Gray.bmp
SetupIconFile=C:\Users\Administrator\Desktop\dd.ico
RestartIfNeededByRun=no
VersionInfoVersion=2016.10.2
VersionInfoTextVersion=2016.10.2
ShowLanguageDialog=auto
;安装密码
;版本号
DisableReadyMemo=yes
;如果设置为 yes,无显示准备安装向导页
[Files]
; Add the Visual Style resource contains resources used for skinning,
; you can also use Microsoft Visual Styles (*.msstyles) resources.
Source: {#ExtendDir}\ISSkin\Styles\Office2007.cjstyles; DestDir: {tmp}; Flags: dontcopy
Source: "C:\Users\Administrator\Desktop\aaa\*"; DestDir: "{app}"; Flags: overwritereadonly ignoreversion
;Source: "C:\Users\Administrator\Desktop\kara.lic";DestDir: "{app}"; Flags: overwritereadonly ignoreversion
;修改为目标目录从 Code 段获取,即为 App 目录的父目录
Source: "C:\Users\Administrator\Desktop\kara.lic";DestDir: "{code:ParentPath}"; Flags: overwritereadonly ignoreversion
[Code]
//获取注册表中的安装目录
Function MyConst(Path: String): String;
begin
Result := ExpandConstant('{pf}') + ‘Adobe Premiere 6.5’; //预定义一个默认安装目录
RegQueryStringValue(HKLM,‘SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Premiere 6.5','InstallLocation',Path);
if Path <> '' then
//Result := ExtractFileDrive(path); //提取根目录
Result := path;
end;
//获取父目录函数
Function ParentPath(Path: String): String;
var
i,k: Integer;
substr: string;
begin
//传入的 Path 参数为空的话,赋值为 App 值
if Path = '' then Path := ExpandConstant('{app}');
substr := '\'; //定义要被查找的字符
Result := Path; //备份 Path,以避免截取子字符串后 Path 值改变
//如果 Result 最后一个字符是 substr 的话,删除最后一个字符
if copy(Result,Length(Result),1) = substr then begin
Result := copy(Result,1,Length(Result) - 1);
end;
//获取 substr 在 Result 中的首个位置值
i := Pos(substr,Result);
//循环截取子字符串,并获取 substr 在子字符串 Result 中的位置值,记录 substr 在原字符串 Path 中的最后位置值
while i > 0 do
begin
k := k + i; //记录每次截取和查找后 substr 在原字符串 Path 中的位置值
Result := Copy(Result,i + 1,Length(Result) - i); //截取找到位置 i + 1 到 Result 最后字符的子字符串
i := Pos(substr,Result); //再次获取 substr 在新 Result 中的首个位置值
end;
//如果找到 substr 值,获取 path 中第一个字符到最后 substr 位置为止的子字符串
if k > 0 then Result := Copy(Path,1,k);
end;
//在选择安装目录页中单击下一步时显示获取父目录函数的测试结果,实际使用时请删除
function NextButtonClick(CurPageID : Integer): Boolean;
begin
Result := true;
if CurPageID = wpSelectDir then begin
msgbox(ExpandConstant('{app}'), mbInformation, MB_OK);
msgbox(ParentPath(ExpandConstant('{app}')), mbInformation, MB_OK);
end;
end;