Writing a Scripting Engine for Windows Scripting Host

The principal requirement for a third-party scripting engine is that it support the ActiveX?IActiveScriptParse COM interface.

The Windows Scripting Host reads and passes the contents of a specified script file to a registered scripting engine using the scripting engine's IActiveScriptParse::ParseScriptText method.

A scripting engine can also call Wshom.ocx, an ActiveX control that supports the IDispatch COM interface. If the scripting engine supports ActiveX control creation in a script, Wshom.ocx can be called from within the script.

If the scripting engine itself calls Wshom.ocx, you should obtain Iwshom.idl, Iwshom.h and Iwshom.iid from the Platform SDK. With these files, you can call methods in Wshom.ocx using the normal COM calling sequence. Wshom.ocx supports a dual interface, aggregation, and the IErrorInfo COM interface.

Example

#include <IWSHom.h>

HRESULT
Use_WSHShell() {
    HRESULT hr;
    IWSHShell* pShell;

    hr = ::CoCreateInstance(CLSID_IWSHShell,
                       NULL,
                       CTX_INPROCSERVER,
                       IID_IWSHShell,
                       (LPVOID*) &pShell );
    if (FAILED(hr)) return hr;

    hr = pShell->Run(bstrCommand,
 &varWindowStyle,
 &varWaitOnReturn,
               &nExitCode );
    pShell->Release();

    return hr;
}