问题
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!
回答1:
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)
来源:https://stackoverflow.com/questions/56419077/how-to-run-a-powershell-script-after-inno-setup-installer