虽然实际上并非如此marrying根据问题的要求,@o_nix 在评论中提出了以下建议https://github.com/idobatter/node-win32ole https://github.com/idobatter/node-win32ole.
我建议这个模块可以满足从 Google 来到这里的人们的许多问题(就像我所做的那样)。
也可以从这里的 npm 获得:https://www.npmjs.com/package/win32ole https://www.npmjs.com/package/win32ole
该模块还有很多示例,例如:https://github.com/idobatter/node-win32ole/blob/dev0.1.3/examples/activex_filesystemobject_sample.js https://github.com/idobatter/node-win32ole/blob/dev0.1.3/examples/activex_filesystemobject_sample.js
var win32ole = require('win32ole');
. . .
var withReadFile = function(filename, callback){
var fso = new ActiveXObject('Scripting.FileSystemObject');
var fullpath = fso.GetAbsolutePathName(filename);
var file = fso.OpenTextFile(fullpath, 1, false); // open to read
try{
callback(file);
}finally{
file.Close();
}
};
var withEachLine = function(filename, callback){
withReadFile(filename, function(file){
// while(file.AtEndOfStream != true) // It works. (without unary operator !)
// while(!file.AtEndOfStream) // It does not work.
while(!file.AtEndOfStream._) // *** It works. oops!
callback(file.ReadLine());
});
};
withEachLine(testfile, function(line){
console.log(line);
});
所以,对我来说,这与结合旧的 WSH 脚本一样好。当然会涉及到调整,但之后就和 WSH 说再见了。
更具体地说,对于当前的问题,这是演示 IE 脚本的片段:https://github.com/idobatter/node-win32ole/blob/master/examples/ie_sample.js https://github.com/idobatter/node-win32ole/blob/master/examples/ie_sample.js
var win32ole = require('win32ole');
. . .
var ie = new ActiveXObject('InternetExplorer.Application');
ie.Visible = true;
for(var i = 0; i < uris.length; ++i){
console.log(uris[i]);
ie.Navigate(uris[i]);
win32ole.sleep(15000, true, true);
}
ie.Quit();