Jump to content

Stopping a VBS script through WSH


Guest joelee

Recommended Posts

Guest joelee

How do i stop a script within the script?

I wish for the script to stop if a certain condition is met.

I thought it was something like "Close" or "Exit"

Link to comment
Share on other sites


Never had to do this, but I dug some info up for you.

There is IActiveScriptSiteInterruptPoll, with the single method QueryContinue(). Both the VBScript and JScript engines query for it, and when you return S_FALSE from QueryContinue(), the script stops executing.

So say you wanted to run a script within a user interface. While the script is running, you display a "please wait" dialog box with a "stop" button on it. When the user presses the button, set your m_bQuit flag to TRUE, and then implement QueryContinue like this.

STDMETHOD(QueryContinue)()

{

// ... pump any windows messages so the stop button can be pressed

if (m_bQuit)

return S_FALSE;

return S_OK;

}

Link to comment
Share on other sites

Guest joelee

I forgot to mention that there won't be any user interaction as it's a script set to run in the night/morning

Never had to do this, but I dug some info up for you.

There is IActiveScriptSiteInterruptPoll, with the single method QueryContinue(). Both the VBScript and JScript engines query for it, and when you return S_FALSE from QueryContinue(), the script stops executing.

So say you wanted to run a script within a user interface. While the script is running, you display a "please wait" dialog box with a "stop" button on it. When the user presses the button, set your m_bQuit flag to TRUE, and then implement QueryContinue like this.

STDMETHOD(QueryContinue)()

{

  // ... pump any windows messages so the stop button can be pressed

 

  if (m_bQuit)

  return S_FALSE;

  return S_OK;

}

Link to comment
Share on other sites

Guest joelee

iceman - cheers mate, works a treat

all - thnaks for help

wscipt.Quit (interrorcode)

intErrorCode

Optional. Integer value returned as the process's exit code. If you do not include the intErrorCode parameter, no value is returned.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...