exception - Powershell exit does not work -
i writing script checks registry value , and exits if 0. (it proceed if value 1.)
if ((get-itemproperty -path hklm:\software\ict\loginscript).proceed -eq 0) { $form.close() exit }
when run script reg value @ 0, fails exit , throws exception instead:
system.management.automation.exitexception: system error. @ system.management.automation.flowcontrolnode.execute(array input, pipe outputpipe, executioncontext context) @ system.management.automation.parsetreenode.execute(array input, pipe outputpipe, arraylist& resultlist, executioncontext context) @ system.management.automation.statementlistnode.executestatement(parsetreenode statement, array input, pipe outputpipe, arraylist& resultlist, executioncontext context) @ system.management.automation.statementlistnode.execute(array input, pipe outputpipe, arraylist& resultlist, executioncontext context) ...
the script using windows forms - not sure if relevant?
edit:
i have reduced script following test:
[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()
and still gives error. if run start-sleep -s 3; exit
code on non-windows form works fine, looks issue tied in windows forms.
thanks,
ben
specifying exit
has same effect exit-pssession
. looking @ stacktrace, think code attempting end interactive session different thread, , that's why fails.
are trying end script? try [runspace]::defaultrunspace.closeasync()
instead.
Comments
Post a Comment