T.Donaldson T.Donaldson - 7 months ago 186
Bash Question

Struggling to run shell xcopy command using shellexec() in inno-setup on windows

I am trying to copy add-on folders/files from the {app} directory to a different folder in Program Files within an inno-setup installer. I have written some code to execute a shell command to do so using xcopy but I cannot get it to work. I have tried all that I can think of permissions wise (shellexecasoriginaluser, flag=runasoriginaluser, PrivilegesRequired=admin). If I type it by hand and run it in cmd it works fine, so one assumes it must be a permissions issue? Any ideas?

Code:

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

[Code]
const
DefaultStatisticsPath = 'C:\Program Files\IBM\SPSS\Statistics\24';

var
SelectStatisticsFolderPage: TInputDirWizardPage;

procedure InitializeWizard;

begin;
ContinueInstall := True;
SelectStatisticsFolderPage := CreateInputDirPage(wpSelectDir,
'Select IBM SPSS Statistics Installation Directory', 'Select a valid IBM SPSS Statistics Installation..',
'Enter the path to a valid installation of IBM SPSS Statistics, then click Next.',
False, DefaultStatisticsPath);
SelectStatisticsFolderPage.Add('');
SelectStatisticsFolderPage.Values[0] := DefaultStatisticsPath;
end;

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;

Answer

The FileName agrument should be xcopy only:

ShellExec('', 'xcopy', '/E /I ...', ...)

The "echo off" parameter is nonsense.


Though for a better error control, you better use native Pascal Script functions:
Inno Setup: copy folder, subfolders and files recursively in Code section