简体   繁体   中英

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!

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 (eg 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM