T.Donaldson
T.Donaldson

Reputation: 115

Using shell xcopy command in Inno Setup

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]

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;

Upvotes: 1

Views: 1339

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202594

  • The FileName argument should be xcopy (or rather xcopy.exe) only.
  • The rest of the command-line goes to the Params argument.
  • The echo off parameter is nonsense.
  • Using the ShellExec for the xcopy is an overkill, use plain Exec.
Exec('xcopy.exe', '/E /I ...', ...)

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


And the last, the simplest and the best way, for your specific case, just use the [Files] section entry with a 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;

Upvotes: 1

Related Questions