我正在尝试将{app}
目录中的附加文件夹/文件复制到Inno Setup安装程序中Program Files
中的其他文件夹。我已经编写了一些代码来执行shell命令来使用xcopy
来执行此操作,但我无法使其工作。我已经尝试了所有我认为明智的权限(shellexecasoriginaluser
,Flag
= runasoriginaluser
,PrivilegesRequired=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;
答案 0 :(得分:1)
FileName
参数应仅为xcopy
(或更确切地说是xcopy.exe
)。Params
参数。echo off
参数是无意义的。 xcopy
使用ShellExec
是一种矫枉过正,请使用普通Exec
。Exec('xcopy.exe', '/E /I ...', ...)
虽然为了更好的错误控制,最好使用原生Pascal脚本功能:
Inno Setup: copy folder, subfolders and files recursively in Code section
对于您的具体情况,最后一种,最简单,最好的方法,只需使用[Files]
部分条目scripted constant:
[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;