mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-06 06:54:58 +00:00
fix
This commit is contained in:
parent
c981fdecec
commit
c60e3b157f
File diff suppressed because it is too large
Load Diff
|
@ -3,8 +3,7 @@
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
var SHELL = require("lib/shell");
|
||||
var WSH = CreateObject("WScript.Shell");
|
||||
var WMI = GetObject("winmgmts:\\\\.\\root\\CIMV2");
|
||||
var FSO = CreateObject("Scripting.FileSystemObject");
|
||||
var WMI = require("lib/wmi");
|
||||
|
||||
exports.VERSIONINFO = "System Module (system.js) version 0.1";
|
||||
exports.global = global;
|
||||
|
@ -57,12 +56,7 @@ exports.isElevated = function() {
|
|||
};
|
||||
|
||||
exports.getOS = function() {
|
||||
try {
|
||||
var colItems = WMI.ExecQuery("SELECT * FROM Win32_OperatingSystem");
|
||||
var enumItems = new Enumerator(colItems);
|
||||
var objItem = enumItems.item();
|
||||
return objItem.Caption.rtrim();
|
||||
} catch (e) {}
|
||||
return WMI.execQuery("SELECT * FROM Win32_OperatingSystem").fetch().get("Caption").rtrim();
|
||||
};
|
||||
|
||||
exports.getDCName = function() {
|
||||
|
@ -74,21 +68,11 @@ exports.getDCName = function() {
|
|||
};
|
||||
|
||||
exports.getArch = function() {
|
||||
try {
|
||||
var colItems = WMI.ExecQuery("SELECT * FROM Win32_OperatingSystem");
|
||||
var enumItems = new Enumerator(colItems);
|
||||
var objItem = enumItems.item();
|
||||
return objItem.OSArchitecture;
|
||||
} catch (e) {}
|
||||
return WMI.execQuery("SELECT * FROM Win32_OperatingSystem").fetch().get("OSArchitecture");
|
||||
};
|
||||
|
||||
exports.getUUID = function() {
|
||||
try {
|
||||
var colItems = WMI.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct");
|
||||
var enumItems = new Enumerator(colItems);
|
||||
var objItem = enumItems.item();
|
||||
return objItem.UUID.toLowerCase();
|
||||
} catch (e) {}
|
||||
return WMI.execQuery("SELECT * FROM Win32_ComputerSystemProduct").fetch().get("UUID").toLowerCase();
|
||||
};
|
||||
|
||||
exports.getCurrentWorkingDirectory = function() {
|
||||
|
@ -131,35 +115,11 @@ exports.getCurrentScriptName = function() {
|
|||
};
|
||||
|
||||
exports.getNetworkInterfaces = function() {
|
||||
var wbemFlagReturnImmediately = 0x10;
|
||||
var wbemFlagForwardOnly = 0x20;
|
||||
var rows = [];
|
||||
|
||||
var colItems = WMI.ExecQuery(
|
||||
"SELECT * FROM Win32_NetworkAdapterConfiguration",
|
||||
"WQL",
|
||||
wbemFlagReturnImmediately | wbemFlagForwardOnly
|
||||
);
|
||||
|
||||
var enumItems = new Enumerator(colItems);
|
||||
for (; !enumItems.atEnd(); enumItems.moveNext()) {
|
||||
var objItem = enumItems.item();
|
||||
rows.push({
|
||||
Caption: (objItem.Caption || ""),
|
||||
IPAddress: (objItem.IPAddress || []).join(','),
|
||||
MACAddress: (objItem.MACAddress || "")
|
||||
});
|
||||
}
|
||||
|
||||
return rows;
|
||||
return WMI.execQuery("SELECT * FROM Win32_NetworkAdapterConfiguration").fetchAll();
|
||||
};
|
||||
|
||||
exports.getProcesses = function() {
|
||||
var processes = [];
|
||||
var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");
|
||||
var query = "Select * From Win32_Process";
|
||||
var result = wmi.ExecQuery(query);
|
||||
return (new Enumerator(result)).toArray();
|
||||
return WMI.execQuery("Select * From Win32_Process").fetchAll();
|
||||
};
|
||||
|
||||
exports.killProcess = function(pid) {
|
||||
|
@ -189,13 +149,5 @@ exports.createShortcut = function(shoutcutName, fileName) {
|
|||
};
|
||||
|
||||
exports.ping = function(address) {
|
||||
var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");
|
||||
var query = "Select * From win32_PingStatus where address='" + address + "'";
|
||||
//var query = squel.select().from("Win32_PingStatus").where("address = ?", address).toString();
|
||||
|
||||
var colItems = wmi.ExecQuery(query);
|
||||
var enumItems = new Enumerator(colItems);
|
||||
var objItem = enumItems.item();
|
||||
|
||||
return objItem.ResponseTime;
|
||||
return WMI.execQuery("Select * From Win32_PingStatus where address='" + address + "'").fetch().get("ResponseTime");
|
||||
};
|
||||
|
|
53
lib/wmi.js
Normal file
53
lib/wmi.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// WMI(Windows Management Instrumentation) API
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var WMIObject = function() {
|
||||
var wbemFlagReturnImmediately = 0x10;
|
||||
var wbemFlagForwardOnly = 0x20;
|
||||
|
||||
this.interface = null;
|
||||
this.cursor = {};
|
||||
this.current = {};
|
||||
|
||||
this.create = function() {
|
||||
this.interface = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");
|
||||
return this;
|
||||
};
|
||||
this.execQuery = function(query) {
|
||||
try {
|
||||
var result = this.interface.ExecQuery(query, "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);
|
||||
this.cursor = new Enumerator(result);
|
||||
} catch(e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
this.fetch = function() {
|
||||
if (!this.cursor.atEnd()) {
|
||||
this.current = this.cursor.item();
|
||||
this.cursor.moveNext();
|
||||
}
|
||||
return this;
|
||||
};
|
||||
this.fetchAll = function() {
|
||||
return this.cursor.toArray();
|
||||
};
|
||||
this.get = function(key) {
|
||||
if (key in this.current) {
|
||||
return this.current[key];
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
this.create();
|
||||
};
|
||||
|
||||
exports.execQuery = function(query) {
|
||||
return (new WMIObject()).execQuery(query);
|
||||
};
|
||||
|
||||
exports.VERSIONINFO = "WMI interface (wmi.js) version 0.1";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
Loading…
Reference in New Issue
Block a user