Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a PowerShell Script after Inno Setup installer

I have a PowerShell script that modifies some preference files that I'm trying to have run after my Inno Setup installer is completed. Haven't found a working solution for this yet. My goal is to embed this in the file, or code, so I don't have to ship multiple files, just the installer. Thanks!

like image 864
code4days Avatar asked Jun 02 '19 21:06

code4days


People also ask

How do I launch a PowerShell script?

In File Explorer (or Windows Explorer), right-click the script file name and then select "Run with PowerShell". The "Run with PowerShell" feature starts a PowerShell session that has an execution policy of Bypass, runs the script, and closes the session.

How do I make an inno file executable?

Go to Menu, Project, then Compile to compile and create the setup file. This will create a complete installer. Run the Setup and your application will be installed correctly. Innosetup offers an awesome alternative to create great looking Installers for free.

What is Inno Setup file?

Inno Setup is a free software script-driven installation system created in Delphi by Jordan Russell. The first version was released in 1997.

What language does Inno Setup use?

Inno Setup's [Code] section uses Pascal (or Pascal Script to be more exact, thanks to TLama), likely because Inno Setup itself is written in Pascal Delphi.


1 Answers

To execute a command after an installation finishes, add an entry to [Run] section.


If the PowerShell code is trivial, you can executed it without any script file directly from PowerShell command-line with -Command switch:

[Run]
Filename: "powershell.exe"; Parameters: \
  "-ExecutionPolicy Bypass -Command [System.IO.File]::WriteAllText('my.ini', 'foo=1')"; \
  WorkingDir: {app}; Flags: runhidden

Regarding the -ExecutionPolicy Bypass: As you will be executing this on systems you do not control, it's likely that some/most will have the default PowerShell settings, that restricts execution of commands. To overcome that you need this switch.


If you need a script, you need to "install" it (e.g. to a temporary folder of the installation) and run it from there.

[Files]
Source: "setup.ps1"; DestDir: "{tmp}"

[Run]
Filename: "powershell.exe"; \
  Parameters: "-ExecutionPolicy Bypass -File ""{tmp}\setup.ps1"""; \
  WorkingDir: {app}; Flags: runhidden

(the temporary folder gets automatically deleted when the installer finishes)

like image 130
Martin Prikryl Avatar answered Sep 27 '22 23:09

Martin Prikryl