在Inno Setup中使用shell xcopy命令
问题描述:
我试图将{app}
目录中的附加文件夹/文件复制到Inno Setup安装程序中的Program Files
中的其他文件夹中。我写了一些代码来执行一个shell命令来使用xcopy
,但是我无法使它工作。我试过所有我能想到的权限(shellexecasoriginaluser
,Flag
= runasoriginaluser
,PrivilegesRequired=admin
)。如果我手工输入并运行它cmd
它工作正常,所以人们认为它必须是权限问题?有任何想法吗?在Inno Setup中使用shell xcopy命令
代码:
[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
参数是无稽之谈。 - 对
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;
非常感谢!我在这工作了几个小时 –
不客气。尽管我已经意识到还有更好的方法来满足您的特殊需求。看到我更新的答案。 –