mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-14 13:41:05 +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 SHELL = require("lib/shell");
|
||||||
var WSH = CreateObject("WScript.Shell");
|
var WSH = CreateObject("WScript.Shell");
|
||||||
var WMI = GetObject("winmgmts:\\\\.\\root\\CIMV2");
|
var WMI = require("lib/wmi");
|
||||||
var FSO = CreateObject("Scripting.FileSystemObject");
|
|
||||||
|
|
||||||
exports.VERSIONINFO = "System Module (system.js) version 0.1";
|
exports.VERSIONINFO = "System Module (system.js) version 0.1";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
|
@ -57,12 +56,7 @@ exports.isElevated = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getOS = function() {
|
exports.getOS = function() {
|
||||||
try {
|
return WMI.execQuery("SELECT * FROM Win32_OperatingSystem").fetch().get("Caption").rtrim();
|
||||||
var colItems = WMI.ExecQuery("SELECT * FROM Win32_OperatingSystem");
|
|
||||||
var enumItems = new Enumerator(colItems);
|
|
||||||
var objItem = enumItems.item();
|
|
||||||
return objItem.Caption.rtrim();
|
|
||||||
} catch (e) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getDCName = function() {
|
exports.getDCName = function() {
|
||||||
|
@ -74,21 +68,11 @@ exports.getDCName = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getArch = function() {
|
exports.getArch = function() {
|
||||||
try {
|
return WMI.execQuery("SELECT * FROM Win32_OperatingSystem").fetch().get("OSArchitecture");
|
||||||
var colItems = WMI.ExecQuery("SELECT * FROM Win32_OperatingSystem");
|
|
||||||
var enumItems = new Enumerator(colItems);
|
|
||||||
var objItem = enumItems.item();
|
|
||||||
return objItem.OSArchitecture;
|
|
||||||
} catch (e) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getUUID = function() {
|
exports.getUUID = function() {
|
||||||
try {
|
return WMI.execQuery("SELECT * FROM Win32_ComputerSystemProduct").fetch().get("UUID").toLowerCase();
|
||||||
var colItems = WMI.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct");
|
|
||||||
var enumItems = new Enumerator(colItems);
|
|
||||||
var objItem = enumItems.item();
|
|
||||||
return objItem.UUID.toLowerCase();
|
|
||||||
} catch (e) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getCurrentWorkingDirectory = function() {
|
exports.getCurrentWorkingDirectory = function() {
|
||||||
|
@ -131,35 +115,11 @@ exports.getCurrentScriptName = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getNetworkInterfaces = function() {
|
exports.getNetworkInterfaces = function() {
|
||||||
var wbemFlagReturnImmediately = 0x10;
|
return WMI.execQuery("SELECT * FROM Win32_NetworkAdapterConfiguration").fetchAll();
|
||||||
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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getProcesses = function() {
|
exports.getProcesses = function() {
|
||||||
var processes = [];
|
return WMI.execQuery("Select * From Win32_Process").fetchAll();
|
||||||
var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");
|
|
||||||
var query = "Select * From Win32_Process";
|
|
||||||
var result = wmi.ExecQuery(query);
|
|
||||||
return (new Enumerator(result)).toArray();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.killProcess = function(pid) {
|
exports.killProcess = function(pid) {
|
||||||
|
@ -189,13 +149,5 @@ exports.createShortcut = function(shoutcutName, fileName) {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.ping = function(address) {
|
exports.ping = function(address) {
|
||||||
var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");
|
return WMI.execQuery("Select * From Win32_PingStatus where address='" + address + "'").fetch().get("ResponseTime");
|
||||||
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;
|
|
||||||
};
|
};
|
||||||
|
|
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