Update wmi.js

This commit is contained in:
Namhyeon Go 2022-04-11 11:15:30 +09:00 committed by GitHub
parent 8eb7e2ede0
commit 157d723b44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,14 +25,17 @@ var WMIQueryObject = function() {
} }
return this; return this;
}; };
this.setComputer = function(computer) { this.setComputer = function(computer) {
this.computer = computer; this.computer = computer;
return this; return this;
}; };
this.setNamespace = function(namespace) { this.setNamespace = function(namespace) {
this.namespace = namespace; this.namespace = namespace;
return this; return this;
}; };
this.execQuery = function(query) { this.execQuery = function(query) {
try { try {
var result = this.interface.ExecQuery(query, "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly); var result = this.interface.ExecQuery(query, "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);
@ -42,6 +45,7 @@ var WMIQueryObject = function() {
} }
return this; return this;
}; };
this.fetch = function() { this.fetch = function() {
if (!this.cursor.atEnd()) { if (!this.cursor.atEnd()) {
this.current = this.cursor.item(); this.current = this.cursor.item();
@ -49,9 +53,15 @@ var WMIQueryObject = function() {
} }
return this; return this;
}; };
this.fetchAll = function() { this.fetchAll = function() {
return this.cursor.toArray(); return this.cursor.toArray();
}; };
this.fetchAll2 = function() {
return this.cursor.toArray2();
};
this.get = function(key) { this.get = function(key) {
if (key in this.current) { if (key in this.current) {
return this.current[key]; return this.current[key];
@ -79,16 +89,20 @@ var WMIClassObject = function() {
this.classObject = this.interface.Get(className); this.classObject = this.interface.Get(className);
return this; return this;
}; };
this.create = function() { this.create = function() {
this.instance = this.classObject.SpawnInstance_(); this.instance = this.classObject.SpawnInstance_();
return this; return this;
}; };
this.getAttribute = function(key) { this.getAttribute = function(key) {
return this.instance[key]; return this.instance[key];
}; };
this.setAttribute = function(key, value) { this.setAttribute = function(key, value) {
this.instance[key] = value; this.instance[key] = value;
}; };
this.getInstance = function() { this.getInstance = function() {
return this.instance; return this.instance;
}; };
@ -99,10 +113,12 @@ var WMIClassObject = function() {
this.methodObject = this.classObject.Methods_.Item(methodName); this.methodObject = this.classObject.Methods_.Item(methodName);
return this; return this;
}; };
this.setParameter = function(key, value) { this.setParameter = function(key, value) {
this.inParams[key] = value; this.inParams[key] = value;
return this; return this;
}; };
this.setParameters = function(params) { this.setParameters = function(params) {
if (typeof(params) !== "undefined") { if (typeof(params) !== "undefined") {
for (k in params) { for (k in params) {
@ -111,6 +127,7 @@ var WMIClassObject = function() {
} }
return this; return this;
}; };
this.execute = function() { this.execute = function() {
var params = this.methodObject.InParameters.SpawnInstance_(); var params = this.methodObject.InParameters.SpawnInstance_();
for (k in this.parameters) { for (k in this.parameters) {
@ -119,6 +136,7 @@ var WMIClassObject = function() {
this.outParams = this.classObject.ExecMethod_(this.methodName, params); this.outParams = this.classObject.ExecMethod_(this.methodName, params);
return this; return this;
}; };
this.get = function(key) { this.get = function(key) {
if (key in this.outParams) { if (key in this.outParams) {
return this.outParams[key]; return this.outParams[key];
@ -138,4 +156,4 @@ exports.setClass = function(className) {
exports.VERSIONINFO = "WMI interface (wmi.js) version 0.1"; exports.VERSIONINFO = "WMI interface (wmi.js) version 0.1";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;