[英]How to cancel NSIS Installer after executed powershell script was canceled?
For my software suite I created an installer with NSIS. 对于我的软件套件,我使用NSIS创建了一个安装程序。 This installer includes a powershellscript with a GUI.
该安装程序包括带有GUI的powershellscript。 I want to cancel the installation process after the user has clicked the cancelbutton in the powershell gui.
我想在用户单击Powershell gui中的cancel按钮后取消安装过程。
The script creates a powershell gui with a listbox. 该脚本使用列表框创建一个powershell gui。 The listbox-item will be written in a txt-file.
列表框项目将被写入txt文件中。 There are two buttons: One for OK - to write the item in the file, the other button is a cancel button.
有两个按钮:一个用于“确定”-将项目写入文件,另一个按钮是“取消”按钮。 After the ok-button was clicked, the second form opens.
单击确定按钮后,将打开第二个表单。
Some code snippets from the powershellscript: powershellscript中的一些代码片段:
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
if('Ok' -eq $form.ShowDialog())
{
$msg = "Item copied to txt-file"
[System.Windows.Forms.MessageBox]::Show($msg,"Confirmation",0)
}
With this instruction I call the PS-Script in NSIS: 通过此指令,我在NSIS中调用PS脚本:
ExecWait "powershell -ExecutionPolicy Bypass -WindowStyle Hidden -File nameofscript.ps1 -FFFeatureOff"
If you return an exit code from your PowerShell on cancel, you can handle that from the NSIS script: 如果在取消时从PowerShell返回退出代码,则可以从NSIS脚本处理该退出代码:
Powershell: 电源外壳:
if ($form.ShowDialog() -eq [System.Windows.Forms.DialogResult]::Cancel)
{
exit 1
}
NSIS: NSIS:
ClearErrors
ExecWait "powershell -ExecutionPolicy Bypass -WindowStyle Hidden -File nameofscript.ps1 -FFFeatureOff"
IfErrors 0 noError
; Handle error here
noError:
See also: how to get the exit code of other application in nsis 另请参阅: 如何在nsis中获取其他应用程序的退出代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.