npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@devscholar/vbs-engine-js

v1.1.1

Published

A VBScript engine written in TypeScript

Downloads

583

Readme

VBSEngineJS

A VBScript engine implemented in TypeScript, supporting VBScript code execution in browser and Node.js environments.

Installation

npm install

Running Examples

See quick-start.md for more information.

API Reference

The VbsEngine class provides an API similar to Microsoft's MSScriptControl:

Methods

| Method | Description | |--------|-------------| | addCode(code: string) | Adds script code to the engine (function/class definitions) | | executeStatement(statement: string) | Executes a single VBScript statement | | run(procedureName: string, ...args) | Calls a function and returns the result | | eval(expression: string) | Evaluates an expression and returns the result | | addObject(name: string, object: unknown, addMembers?: boolean) | Exposes a JavaScript object to VBScript | | clearError() | Clears the last error | | destroy() | Cleans up resources (browser mode) |

Properties

| Property | Type | Description | |----------|------|-------------| | error | VbsError \| null | The last error that occurred, or null |

Example Usage

import { VbsEngine } from './src/index.ts';

const engine = new VbsEngine();

// Define functions
engine.addCode(`
  Function Multiply(a, b)
      Multiply = a * b
  End Function
  
  Class Calculator
      Public Function Add(x, y)
          Add = x + y
      End Function
  End Class
`);

// Call functions
const product = engine.run('Multiply', 6, 7);
console.log(product);  // 42

// Expose JavaScript objects
const myApp = {
  name: 'MyApp',
  version: '1.0.0',
  greet: (name: string) => `Hello, ${name}!`
};
engine.addObject('MyApp', myApp, true);

// Use exposed object in VBScript
engine.executeStatement('result = MyApp.greet("World")');
const result = engine.eval('result');
console.log(result);  // "Hello, World!"

// Error handling
engine.executeStatement('x = CInt("not a number")');
if (engine.error) {
  console.log('Error:', engine.error.description);
}

COM / ActiveX Integration (Node.js on Windows)

VBScript's CreateObject and GetObject depend on a host-provided COM backend. In Node.js, wire up @devscholar/node-ps1-dotnet before running scripts:

npm install @devscholar/node-ps1-dotnet
import { VbsEngine } from '@devscholar/vbs-engine-js';
import { ActiveXObject, GetObject } from '@devscholar/node-ps1-dotnet/activex';

// Expose COM constructors to the engine
globalThis.ActiveXObject = ActiveXObject;
globalThis.GetObject = GetObject;

const engine = new VbsEngine();

CreateObject

engine.executeStatement(`
  Set fso = CreateObject("Scripting.FileSystemObject")
  MsgBox fso.GetAbsolutePathName(".")
`);

GetObject — bind to a running instance

// GetObject(, "Excel.Application") — gets a running Excel instance
engine.executeStatement(`
  Set xl = GetObject(, "Excel.Application")
  MsgBox xl.Version
`);

GetObject — bind to a WMI moniker

engine.executeStatement(`
  Set wmi = GetObject("winmgmts:")
  For Each os In wmi.ExecQuery("SELECT * FROM Win32_OperatingSystem")
    MsgBox os.Caption & " " & os.Version
  Next
`);

GetObject — bind to a file

engine.executeStatement(`
  Set doc = GetObject("C:\Reports\sales.xls")
  MsgBox doc.Name
`);

Note: COM/ActiveX requires Windows. On other platforms CreateObject returns a dummy object and GetObject returns Nothing.

Security Warning

⚠️ Important Security Considerations

The VBScript engine executes arbitrary code provided by users or external sources. This presents significant security risks:

  • Code Injection: Malicious VBScript code can access and modify JavaScript objects exposed via addObject()
  • Infinite Loops: VBScript code can contain infinite loops that can hang the browser/Node.js process
  • Resource Exhaustion: Poorly written scripts can consume excessive memory or CPU
  • DOM Manipulation: In browser mode, scripts can access and modify the DOM

Engine Options

interface VbsEngineOptions {
  mode?: 'general' | 'browser';  // Default: 'general'
  injectGlobalThis?: boolean;    // Default: true
  maxExecutionTime?: number;     // Default: -1 (unlimited)
  
  // Browser mode only:
  parseScriptElement?: boolean;       // Default: true
  parseInlineEventAttributes?: boolean; // Default: true
  parseEventSubNames?: boolean;       // Default: true
  parseVbsProtocol?: boolean;         // Default: true
  overrideJsEvalFunctions?: boolean;  // Default: true
}

| Option | Type | Default | Description | |--------|------|---------|-------------| | mode | 'general' \| 'browser' | 'auto' | Engine mode. Auto-detects based on environment: 'browser' in browser, 'general' in Node.js. Use 'browser' for web applications | | injectGlobalThis | boolean | true | Enable IE-style global variable sharing between VBScript and JavaScript | | injectVBArrayToGlobalThis | boolean | true | Expose VBArray as globalThis.VBArray for legacy code compatibility | | maxExecutionTime | number | -1 | Maximum script execution time in milliseconds. -1 means unlimited | | parseScriptElement | boolean | true | Automatically process <script type="text/vbscript"> tags (browser mode) | | parseInlineEventAttributes | boolean | true | Process inline event attributes like onclick="vbscript:..." (browser mode) | | parseEventSubNames | boolean | true | Auto-bind event handlers from Sub names like Button1_OnClick (browser mode) | | parseVbsProtocol | boolean | true | Handle vbscript: protocol in links (browser mode) | | overrideJsEvalFunctions | boolean | true | Override JS eval functions (eval,setTimeout,setInterval) to support VBScript (browser mode) |

Example Usage

// General mode (Node.js or browser without auto-parsing)
const engine = new VbsEngine({
  injectGlobalThis: true,
  maxExecutionTime: 5000
});

// Browser mode (auto-parsing enabled)
const browserEngine = new VbsEngine({
  mode: 'browser',
  parseScriptElement: true,
  parseInlineEventAttributes: true,
  parseEventSubNames: true
});

Compatibility

See docs/compatibility.md for details.