Note that there are some explanatory texts on larger screens.

plurals
  1. POPowershell exit does not work
    text
    copied!<p>I am writing a script which checks for a registry value and and exits if is 0. (It will proceed if the value is 1.)</p> <pre><code> if ((Get-ItemProperty -path HKLM:\SOFTWARE\ICT\LoginScript).proceed -eq 0) { $form.close() exit } </code></pre> <p>When I run the script with the reg value at 0, it fails to exit and throws an exception instead:</p> <pre><code>System.Management.Automation.ExitException: System error. at System.Management.Automation.FlowControlNode.Execute(Array input, Pipe outputPipe, ExecutionContext context) at System.Management.Automation.ParseTreeNode.Execute(Array input, Pipe outputPipe, ArrayList&amp; resultList, ExecutionContext context) at System.Management.Automation.StatementListNode.ExecuteStatement(ParseTreeNode statement, Array input, Pipe outputPipe, ArrayList&amp; resultList, ExecutionContext context) at System.Management.Automation.StatementListNode.Execute(Array input, Pipe outputPipe, ArrayList&amp; resultList, ExecutionContext context) ... </code></pre> <p>The script is using windows forms - not sure if that is relevant?</p> <p>EDIT:</p> <p>I have reduced the script to the following to test:</p> <pre><code>[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $Form = New-Object System.Windows.Forms.Form $Form.Add_Shown({ $Form.Activate(); start-sleep -s 3; exit; $form.close() }) $Form.ShowDialog() </code></pre> <p>And this still gives the error. If I run the <code>start-sleep -s 3; exit</code> code on a non-windows form it works fine, so it looks like the issue is tied in with Windows Forms.</p> <p>Thanks,</p> <p>Ben</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload