Using COM object in NodeJS


Node.JS (http://nodejs.org/) has been a great Javascript-server side tool). Previous posts on this topic can be found [here].

However, the NodeJS does not inherently support the Win32 COM/OLE techniques maybe because it is designed to be platform independent in the first place, like Python, which is similar in the case that you will need to download the win32com package [see here].

How to Call COM Object in NodeJS?

In order to use the COM object in server-side Javascript, you will have to download the win32ole package from npmjs (https://npmjs.org/package/win32ole) website.

npm Using COM object in NodeJS COM/OLE implementation interpreter / compiler javascript nodejs programming languages recursive string technical tools / utilities tricks windows

Upon successful installation, you will find the folder node_modules at the drive where you initiative the command.

npm2 Using COM object in NodeJS COM/OLE implementation interpreter / compiler javascript nodejs programming languages recursive string technical tools / utilities tricks windows

The following shows the most simple example of using COM object in the server-side Javascript, which is quite similar of using COM object in Python script  [see here] with the help of win32com package.

test Using COM object in NodeJS COM/OLE implementation interpreter / compiler javascript nodejs programming languages recursive string technical tools / utilities tricks windows

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
 *
 * Node.JS Demo using COM
 * https://helloacm.com
*/
 
(function () {
    try {
        var win32ole = require('win32ole');     
        var WSH = win32ole.client.Dispatch('WScript.Shell');
        WSH.popup("Hello, world!");
    } catch (e) {
        console.log(e);
    }
})();
/*
 *
 * Node.JS Demo using COM
 * https://helloacm.com
*/

(function () {
	try {
		var win32ole = require('win32ole');		
		var WSH = win32ole.client.Dispatch('WScript.Shell');
		WSH.popup("Hello, world!");
	} catch (e) {
		console.log(e);
	}
})();

Oh yeah, it succeeds!

test2 Using COM object in NodeJS COM/OLE implementation interpreter / compiler javascript nodejs programming languages recursive string technical tools / utilities tricks windows

You might also be interested in this post: How to Call COM Object in C++ Unmanaged Code?

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
479 words
Last Post: Lock Serial Number to Hardware in Licensing using VMProtect
Next Post: USB OTG (On The Go)

The Permanent URL is: Using COM object in NodeJS

One Response

  1. Ravindra Variagi

Leave a Reply