取消执行的 powershell 脚本后如何取消 NSIS 安装程序?
How to cancel NSIS Installer after executed powershell script was canceled?
对于我的软件套件,我使用 NSIS 创建了一个安装程序。此安装程序包括一个带有 GUI 的 powershellscript。我想在用户单击 powershell gui 中的取消按钮后取消安装过程。
该脚本创建了一个带有列表框的 powershell gui。列表框项目将写入一个 txt 文件。有两个按钮:一个用于确定 - 将项目写入文件,另一个按钮是取消按钮。单击确定按钮后,将打开第二个表单。
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)
}
根据这条指令,我在 NSIS 中调用 PS-脚本:
ExecWait "powershell -ExecutionPolicy Bypass -WindowStyle Hidden -File nameofscript.ps1 -FFFeatureOff"
如果您 return 从 PowerShell 中取消退出代码,您可以从 NSIS 脚本中处理它:
Powershell:
if ($form.ShowDialog() -eq [System.Windows.Forms.DialogResult]::Cancel)
{
exit 1
}
NSIS:
ClearErrors
ExecWait "powershell -ExecutionPolicy Bypass -WindowStyle Hidden -File nameofscript.ps1 -FFFeatureOff"
IfErrors 0 noError
; Handle error here
noError:
另请参阅:how to get the exit code of other application in nsis
对于我的软件套件,我使用 NSIS 创建了一个安装程序。此安装程序包括一个带有 GUI 的 powershellscript。我想在用户单击 powershell gui 中的取消按钮后取消安装过程。
该脚本创建了一个带有列表框的 powershell gui。列表框项目将写入一个 txt 文件。有两个按钮:一个用于确定 - 将项目写入文件,另一个按钮是取消按钮。单击确定按钮后,将打开第二个表单。
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)
}
根据这条指令,我在 NSIS 中调用 PS-脚本:
ExecWait "powershell -ExecutionPolicy Bypass -WindowStyle Hidden -File nameofscript.ps1 -FFFeatureOff"
如果您 return 从 PowerShell 中取消退出代码,您可以从 NSIS 脚本中处理它:
Powershell:
if ($form.ShowDialog() -eq [System.Windows.Forms.DialogResult]::Cancel)
{
exit 1
}
NSIS:
ClearErrors
ExecWait "powershell -ExecutionPolicy Bypass -WindowStyle Hidden -File nameofscript.ps1 -FFFeatureOff"
IfErrors 0 noError
; Handle error here
noError:
另请参阅:how to get the exit code of other application in nsis