在 Inno Setup 中使用 shell xcopy 命令

Using shell xcopy command in Inno Setup

我正在尝试将附加组件 folders/files 从 {app} 目录复制到 Inno Setup 安装程序中 Program Files 中的另一个文件夹。我已经编写了一些代码来使用 xcopy 执行 shell 命令,但我无法让它工作。我已经尝试了所有我能想到的明智的权限(shellexecasoriginaluserFlag=runasoriginaluserPrivilegesRequired=admin)。如果我手动输入它并在 cmd 中输入 运行 它工作正常,所以有人认为它一定是权限问题?有什么想法吗?

代码:

[Files]
Source: "..\Dialogs\*";DestDir: "{app}\Dialogs"; Flags: ignoreversion recursesubdirs 64bit; AfterInstall: WriteExtensionsToInstallFolder();

[Code]

procedure WriteExtensionsToInstallFolder();
var  
  StatisticsInstallationFolder: string;
  pParameter: string;
  runline: string;
  ResultCode: integer;  
begin
  StatisticsInstallationFolder := SelectStatisticsFolderPage.Values[0];
  pParameter := '@echo off' + #13#10
  runline := 'xcopy /E /I /Y "' + ExpandConstant('{app}') + '\Dialogs\*" "' + ExpandConstant(StatisticsInstallationFolder) + '\ext"'
  if not ShellExec('',runline, pParameter, '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
  begin
    MsgBox('Could not copy plugins' + IntToStr(ResultCode) ,mbError, mb_Ok);
  end;
end;
  • FileName 参数应该只是 xcopy(或者 xcopy.exe)。
  • 命令行的其余部分转到 Params 参数。
  • echo off参数是废话。
  • 使用 ShellExec for the xcopy is an overkill, use plain Exec.
Exec('xcopy.exe', '/E /I ...', ...)

尽管为了更好地控制错误,您最好使用本机 Pascal 脚本函数:


最后,最简单也是最好的方法,针对您的具体情况,只需使用带有 scripted constant:

[Files] 部分条目
[Files]
Source: "..\Dialogs\*"; DestDir: "{app}\Dialogs"; Flags: ignoreversion recursesubdirs 64bit;
Source: "..\Dialogs\*"; DestDir: "{code:GetStatisticsInstallationFolder}"; Flags: ignoreversion recursesubdirs 64bit;

[Code]

function GetStatisticsInstallationFolder(Param: String): String;
begin
  Result := SelectStatisticsFolderPage.Values[0];
end;