Update WMI.js

This commit is contained in:
Namhyeon Go 2020-11-15 04:38:23 +09:00
parent 1167c6ab84
commit d0c6cb89f2
2 changed files with 11 additions and 10 deletions

10
app.js
View File

@ -99,15 +99,7 @@ if (typeof(CreateObject) !== "function") {
if (typeof(GetObject) !== "function") {
var GetObject = function(pathName, className) {
var paths = pathName.split("\\");
if (paths[0].indexOf("winmgmts:") > -1) {
var objLocator = CreateObject("WbemScripting.SWbemLocator");
var strComputer = paths[2];
var strNamespace = paths.slice(3).join("\\");
return objLocator.ConnectServer(strComputer, strNamespace);
} else {
console.log("Not supported " + pathName);
}
console.error("Not supported on this environment.");
};
}

View File

@ -12,7 +12,16 @@ var WMIObject = function() {
this.current = {};
this.create = function() {
this.interface = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\" + this.server + "\\root\\cimv2");
try {
if (typeof(GetObject) === "function") {
this.interface = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\" + this.server + "\\root\\cimv2");
} else {
var objLocator = CreateObject("WbemScripting.SWbemLocator");
this.interface = objLocator.ConnectServer(this.server, "\\root\\cimv2");
}
} catch (e) {
console.error(e.message);
}
return this;
};
this.setServer = function(server) {