diff --git a/app.js b/app.js index 3a0b890..59c03ef 100644 --- a/app.js +++ b/app.js @@ -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."); }; } diff --git a/lib/wmi.js b/lib/wmi.js index adfdce5..fe03ca7 100644 --- a/lib/wmi.js +++ b/lib/wmi.js @@ -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) {