How to use InnoSetup in Windows 10 to extract a compressed folder to 'Program Files'?

Issue

I am working on an app that requires a large hierarchy of configuration files. I am trying to use InnoSetup to build the installer. Rather than putting each config file and its path into the .iss file, I put the entire hierarchy into a .zip file. The app needs to be installed into ‘Program Files (x86), and the config files hierarchy needs to be in a folder in the same location as the executable. My installer successfully puts the ‘config.zip’ file in ‘Program Files (x86) with the app’s executable, but I can’t extract the folders and files from the archive. I considered using a self-extracting archive, but the required script for IExpress would just be too unmanageable. I don’t want to include any third-party extraction programs, or rely on finding them on the customer’s computer. And I don’t want to rely on the customer using file explorer to extract the folder.

I am using the following code to extract the archive contents, but it is not working. Nothing is getting extracted.

[Run]
; Unzip the Configuration folder
Filename: "powershell"; Parameters: "-WindowStyle Hidden -Command ""Expand-Archive -Force '{app}\Configuration.zip'"""; Flags: runascurrentuser; Description: "Install Configuration folder hierarchy"

I assume this is a ‘permissions’ problem, but I can’t find the necessary settings to overcome the issue. Here is the whole .iss file:

; Dummy

[Setup]
WizardStyle=modern
SetupLogging=yes
AppName=Dummy
AppVersion=1.0
VersionInfoVersion=1.0
DefaultDirName={commonpf}\Dummy
DefaultGroupName=Dummy
;SourceDir="Dummy"
; If you set 'SourceDir', you must force 'OutputDir' to be where you want it.
;OutputDir="Setup"
OutputBaseFilename={#SetupSetting("AppName")}_Setup

; Files section (i.e. the .exe file)
[Files]
Source: "Dummy.exe"; DestDir: "{app}"
Source: "Configuration.zip"; DestDir: "{app}"

; Icons section - Defines shortcuts to be created.
[Icons]
Name: "{commondesktop}\Dummy"; Filename: "{app}\Dummy.exe"; Tasks: "desktopicons"; Comment: "Dummy Application."
Name: "{commondesktop}\Uninstall Dummy"; Filename: "{uninstallexe}"; Tasks: "desktopicons"; 
Name: "{group}\Dummy"; Filename: "{app}\Dummy.exe"; Comment: "Dummy Application."
Name: "{group}\Uninstall Dummy"; Filename: "{uninstallexe}";

; Tasks section - Defines user-customizable tasks
[Tasks]
Name: "desktopicons"; Description: "Create desktop icons"

; Run section
[Run]
; Unzip the Configuration folder
;Filename: "powershell"; Parameters: "-WindowStyle Hidden -Command ""Expand-Archive -Force 'Configuration.zip'"""; Flags: runhidden; Description: "Install Configuration folder hierarchy"
Filename: "powershell"; Parameters: "-WindowStyle Hidden -Command ""Expand-Archive -Force '{app}\Configuration.zip'"""; Flags: runascurrentuser; Description: "Install Configuration folder hierarchy"

; UninstallDelete section - Clean-up the Configurations folder
[UninstallDelete]
Type: filesandordirs; Name: "{app}\Configuration"
;Type: dirifempty; Name: "{app}"

; End of Script

Additional information: After running the installer, if I run the PowerShell command from a batch file in the folder where the .zip file was installed, I get this:

C:\Program Files (x86)\Dummy>powershell -command "Expand-Archive -Force 'Configuration.zip'"
   New-Item : Access to the path 'Configuration' is denied.
   At
   C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:393 char:25
      + ...             New-Item -Path $resolvedDestinationPath -ItemType Directo ...
      +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         + CategoryInfo          : PermissionDenied: (C:\Program File...y\Configuration:String) [New-Item], UnauthorizedAccessException
         + FullyQualifiedErrorId : CreateDirectoryUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand

Solution

You don’t need a compressed folder. Inno-Setup can handle all of this for you. (Thank you @Bill_Stewart!)

This eliminates the need for the PowerShell call in the [Run] section.

[Files]
Source: "Dummy.exe"; DestDir: "{app}"
Source: "Configuration\*"; DestDir: "{app}\Configuration"; Flags: recursesubdirs createallsubdirs

Answered By – JNygrenLT

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published