nodejs 使用 com组件
npm i winax
winax - npm (npmjs.com)
const com = require('winax')
const req = new com.Object('WinHttp.WinHttpRequest.5.1')
req.Open('GET', "http://192.168.1.1/")
req.Send();
console.log(req.ResponseText)
com.release(req)
const com = require('./node_activex.node');
const req = new com.Object('WinHttp.WinHttpRequest.5.1')
req.Open('GET', "http://192.168.1.1/")
req.Send();
let buf = Buffer.from(req.ResponseBody)
console.log(buf.toString())
req.Release
wmi
const com = require('./node_activex.node')
const ps = wmiQuery('SELECT * FROM Win32_Process')
ps.forEach(e => console.log(e.Caption))
function wmiQuery(wsql) {
let conn = new com.Object('WbemScripting.SWbemLocator')
let svr = conn.ConnectServer('.', '\root\cimv2')
let resp = svr.ExecQuery(wsql)
let list = Array(resp.Count)
for (let i = 0; i < resp.Count; i += 1) {
let properties = resp.ItemIndex(i).Properties_;
let count = properties.Count;
const propEnum = properties._NewEnum;
list[i] = {}
while (count--) {
const prop = propEnum.Next();
if (prop) {
list[i][prop.Name] = prop.Value
}
}
}
svr.Release
return list
}