Microsoft® Windows® Script Interfaces
 Language Reference

HRESULT InterruptScriptThread(
    SCRIPTTHREADID   stidThread,  // identifier of thread
    const EXCEPINFO *pexcepinfo,  // receives error information
    DWORD dwFlags

Interrupts the execution of a running script thread (an event sink, an immediate execution, or a macro invocation). This method can be used to terminate a script that is stuck (in an infinite loop, for example). It can be called from non-base threads without resulting in a non-base callout to host objects or to the IActiveScriptSite method.

[in] Identifier of the thread to interrupt, or one of the following special thread identifier values:

SCRIPTTHREADID_ALL All threads. The interrupt is applied to all script methods currently in progress. Note that unless the caller has requested that the script be disconnected, by calling the IActiveScript::SetScriptState method with the SCRIPTSTATE_DISCONNECTED or SCRIPTSTATE_INITIALIZED flag set, the next scripted event causes script code to run again.
SCRIPTTHREADID_BASE The base thread; that is, the thread in which the scripting engine was instantiated.
SCRIPTTHREADID_CURRENT The currently executing thread.

[in] Address of an EXCEPINFO structure that receives error information associated with the error condition.
[in] Option flags associated with the interruption. Can be one of these values:

SCRIPTINTERRUPT_DEBUG If supported, enter the scripting engine's debugger at the current script execution point.
SCRIPTINTERRUPT_RAISEEXCEPTION If supported by the scripting engine's language, let the script handle the exception. Otherwise, the script method is aborted and the error code is returned to the caller; that is, the event source or macro invoker.