How to stop a script without exception error

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 11 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
albourne
Posts: 4
Last visit: Fri Dec 09, 2022 2:25 am

How to stop a script without exception error

Post by albourne »

Hello,

I am building a script to do some checks (file exists, service exists etc.)

Each check is within its own function.

I made a function (funcExitScript) that all other functions point to on a certain condition, e.g.

function checkthis{
if this ok, ok
elseif this not ok go to funcExitScript
}

Now this works but I cannot stop the script gracefully.
I need the series of functions to stop executing when one of them is having a condition I set and the only thing the user can do is to click on Exit.

Tried using Break and Exit but I get an Unhandled Exception Error (even after setting the global preference to silently continue.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

How to stop a script without exception error

Post by davidc »

Is this a normal script or a GUI script?
What version of PowerShell are you using?
What error message are you getting?

David
David
SAPIEN Technologies, Inc.
User avatar
william.mcgregor
Posts: 2
Last visit: Mon Aug 25, 2014 7:06 pm

How to stop a script without exception error

Post by william.mcgregor »

I am having the same issue. I am creating a package with a form that runs scripts within the package. The form is actually generated by Powershell Studio 2012 in the form of a .pff file.
Even when I generated a pre configured gui form from scratch in the tool, there was no exit commands associated with the exit button, however it does exit the form.
Help would be fantastic
Will
User avatar
william.mcgregor
Posts: 2
Last visit: Mon Aug 25, 2014 7:06 pm

How to stop a script without exception error

Post by william.mcgregor »

Amendment to the above post.
the command "$form1.Close()" will work where you substitute "$form1" for your form name. in the .pff file, go to the designer view, and then click the outer edge of the form. In the properties "Design - {Name}" is the name of the form. Add the command above to the click event of the button and your application will exit.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

How to stop a script without exception error

Post by davidc »

Yes the close method will work or you can also use the DialogResult property of the Button. See the Spotlight on the Button Control for more details:

http://www.sapien.com/blog/2011/06/07/p ... n-control/

If you use $form.Close() it will not end the script execution of an event, so be sure to use a "return" afterwards.

if($failed)
{
$form.Close()
return #Otherwise it will continue to execute the event
}

#continue script
...

David
David
SAPIEN Technologies, Inc.
This topic is 11 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.