Skip to content

node win32ole_Reference

idobatter edited this page Mar 1, 2013 · 9 revisions

node-win32ole_Reference

node-win32ole Reference

Example

var win32ole = require('win32ole');
try{
  var ie = new ActiveXObject('InternetExplorer.Application');
  ie.Visible = true;
  ie.Navigate('http://www.google.com/');
  ie.Document.Forms(0).Item('q').Value = '"node.js"';
  win32ole.sleep(15000, true, true);
  ie.Quit();
}catch(e){
  console.log('*** exception catched ***\n' + e);
}

Initialize

You should better to catch any exceptions.

var win32ole = require('win32ole');
try{
  // access to ActiveXObject / COM by node-win32ole
}catch(e){
  console.log('*** exception catched ***\n' + e);
}

Dispatch ( CreateObject )

You may check returned value is undefined or not.

  var ie = new ActiveXObject('InternetExplorer.Application');
  // or
  var ie = win32ole.client.Dispatch('InternetExplorer.Application');

get

Obsoleted.

  var resultObj = ie.get('propertyname');
  // or
  var resultObj = ie.get('propertyname', [arg0, arg1, arg2, ...]);

set

Obsoleted.

  var value = 'url';
  ie.set('propertyname', value);

call

Obsoleted.

  ie.call('methodname');
  ie.call('methodname', [arg0, arg1, arg2, ...]);
  // or
  var resultObj = ie.call('methodname');
  var resultObj = ie.call('methodname', [arg0, arg1, arg2, ...]);

Metamorphoses

You can write above codes more easily.

  var ie = new ActiveXObject('InternetExplorer.Application');
  ie.Visible = true;
  ie.Navigate('http://www.google.com/');
  ie.Document.Forms(0).Item('q').Value = '"node.js"';
  win32ole.sleep(15000, true, true);
  ie.Quit();

Old style (using caller/getter/setter) was obsoleted.

  var ie = new ActiveXObject('InternetExplorer.Application');
  ie.set('Visible', true);
  ie.call('Navigate', ['http://www.google.com/']);
  ie.get('Document').call('Forms', [0]).call('Item', ['q']).set('Value', '"node.js"');
  win32ole.sleep(15000, true, true);
  ie.call('Quit');

Other built in functions

  • win32ole.version(void) // returns version string
  • win32ole.printACP(utf8string) // Utf8 to .ACP
  • win32ole.print(utf8string) // ASCII
  • win32ole.gettimeofday(struct timeval &tv, null) // now arg2 is not used
  • win32ole.sleep(long milliseconds, bool withmessage=false, bool with\n=false)
  • win32ole.force_gc_extension(long flag) // now flag is dummy
  • win32ole.force_gc_internal(long flag, string) // now flag is dummy