ipollock
Posts: 137
Joined: Wed Aug 31, 2016 10:46 am

File copy from souce A to location B, C and D.

Currently our installer is around 1GB in size. We want to reduce this by copying a file at install time from one location to three additional locations.
The file is 150Mb in size so potentially by not carrying it 4 times inside the installer then we could reduce the installer by 450Mb.

So in order to do this are we able to include the file inside the installer once and then near the end of the install, copy it to the other three places. Ending up with four copies of the file. And a smaller overall install file :)

Any suggestions welcome.

I have tried this using powershell and a custom action however the process fails the installer at the copy point.

Thanks.
Catalin
Posts: 6608
Joined: Wed Jun 13, 2018 7:49 am

Re: File copy from souce A to location B, C and D.

Hello,

This should be fairly easy to achieve, I am not quite sure why this is failing.

First of all, could you please let me know how you are copying the file (e.g. the PS script you are using)?

In addition to that, please make sure the custom action is scheduled as it follows:

- after the "Add resources" action group (so we execute the custom action after the file is copied on the machine), with the "Execution Time" set to "When the system is being modified (deferred)"

- if you copy in a per-machine location that requires administrator privileges, please make sure to check the "Run under the LocalSystem" account option

Regarding the script itself, you could use the "Copy-Item" cmdlet from PowerShell.

Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
ipollock
Posts: 137
Joined: Wed Aug 31, 2016 10:46 am

Re: File copy from souce A to location B, C and D.

Hi Catalin,

I was able to achieve a solution for copying the files and also removing the files during uninstall by using custom actions.
Note that installer won't automatically pull the copied files out during uninstall as they were not put there by the installers normal process.
By default they are left behind like other files that are added post install, along with their folder so my uninstall script includes removing the folders to the file and the files themselves.

Here is how i did it using a Powershell Inline Script with Execution Stage Condition set to Install.

# Get APPDIR from AI and store it
$InstPath = AI_GetMsiProperty APPDIR

# Set up variables for file tranfer
$FileSource = "ApplicationA\FolderA\download\SourceFile.exe"
$AppA = Join-Path -Path $InstPath -ChildPath $FileSource
$AppB = Join-Path -Path $InstPath -ChildPath "AppB\downloads"
$AppC = Join-Path -Path $InstPath -ChildPath "AppC\Downloads"
$AppD = Join-Path -Path $InstPath -ChildPath "AppD\Downloads"

# Copy files to other folders.
Copy-Item -Path $AppA -Destination $AppB
Copy-Item -Path $AppA -Destination $AppC
Copy-Item -Path $AppA -Destination $AppD

And for removing during uninstall using a Powershell Inline Script with Execution Stage Condition set to Uninstall.

# Get APPDIR from AI and store
$InstPath = AI_GetMsiProperty APPDIR

# Set up variables for file removal
$AppB = Join-Path -Path $InstPath -ChildPath "AppB\downloads"
$AppC = Join-Path -Path $InstPath -ChildPath "AppC\downloads"
$AppD = Join-Path -Path $InstPath -ChildPath "AppD\downloads"

Remove-Item -LiteralPath $AppB -Force -Recurse
Remove-Item -LiteralPath $AppC -Force -Recurse
Remove-Item -LiteralPath $AppD -Force -Recurse

Best regards,
Ian
Catalin
Posts: 6608
Joined: Wed Jun 13, 2018 7:49 am

Re: File copy from souce A to location B, C and D.

Hello Ian,

Thank you for your followup on this and for sharing your solution with us!

Indeed, the modification done by the custom actions are not taken in account during uninstall because the Windows Installer can not know of those actions (it only accounts the standard actions which are proprietary to itself).

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”