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!
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.
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.
Inno Setup is a free software script-driven installation system created in Delphi by Jordan Russell. The first version was released in 1997.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With