T.Donaldson T.Donaldson - 1 year ago 315
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?


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

DefaultStatisticsPath = 'C:\Program Files\IBM\SPSS\Statistics\24';

SelectStatisticsFolderPage: TInputDirWizardPage;

procedure InitializeWizard;

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.Values[0] := DefaultStatisticsPath;

procedure WriteExtensionsToInstallFolder();
StatisticsInstallationFolder: string;
pParameter: string;
runline: string;
ResultCode: integer;
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
MsgBox('Could not copy plugins' + IntToStr(ResultCode) ,mbError, mb_Ok);

Answer Source

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