How to run a PowerShell Script after Inno Setup installer

依然范特西╮ 提交于 2020-12-30 01:34:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!