在Inno Setup安装程序之后如何运行PowerShell脚本 [英] How to run a PowerShell Script after Inno Setup installer

查看:133
本文介绍了在Inno Setup安装程序之后如何运行PowerShell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PowerShell脚本,可以在Inno Setup安装程序完成后修改一些我要运行的首选项文件.尚未找到可行的解决方案.我的目标是将此文件嵌入文件或代码中,因此我不必附带多个文件,只需安装程序即可.谢谢!

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.

如果PowerShell代码很简单,则可以直接使用

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

关于 -ExecutionPolicy绕过 :由于您将在不受控制的系统上执行此操作,因此某些/大多数将具有默认的PowerShell设置,从而限制了命令的执行.要克服这一点,您需要此开关.

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)

这篇关于在Inno Setup安装程序之后如何运行PowerShell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆