mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-14 05:31:03 +00:00
Update system.js, wmi.js
This commit is contained in:
parent
2aa60e0dcf
commit
0fdc69222f
|
@ -11,25 +11,19 @@ exports.require = global.require;
|
||||||
|
|
||||||
exports.createProcess = function(cmd) {
|
exports.createProcess = function(cmd) {
|
||||||
var SW_HIDE = 0;
|
var SW_HIDE = 0;
|
||||||
var pid = 0;
|
var si = WMI.setClass("Win32_ProcessStartup").create();
|
||||||
|
|
||||||
var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2")
|
|
||||||
var si = wmi.Get("Win32_ProcessStartup").SpawnInstance_();
|
|
||||||
si.ShowWindow = SW_HIDE;
|
si.ShowWindow = SW_HIDE;
|
||||||
si.CreateFlags = 16777216;
|
si.CreateFlags = 16777216;
|
||||||
si.X = si.Y = si.XSize = si.ySize = 1;
|
si.X = si.Y = si.XSize = si.ySize = 1;
|
||||||
|
|
||||||
//wmi.Get("Win32_Process").Create(cmd, null, si, pid);
|
//wmi.Get("Win32_Process").Create(cmd, null, si, pid);
|
||||||
var w32proc = wmi.Get("Win32_Process");
|
var process = WMI.setClass("Win32_Process").setMethod("Create").setParameters({
|
||||||
|
"CommandLine": cmd,
|
||||||
|
"CurrentDirectory": null,
|
||||||
|
"ProcessStartupInformation": si
|
||||||
|
}).execute();
|
||||||
|
|
||||||
var method = w32proc.Methods_.Item("Create");
|
return process.get("ProcessID");
|
||||||
var inParams = method.InParameters.SpawnInstance_();
|
|
||||||
inParams.CommandLine = cmd;
|
|
||||||
inParams.CurrentDirectory = null;
|
|
||||||
inParams.ProcessStartupInformation = si;
|
|
||||||
|
|
||||||
var outParams = w32proc.ExecMethod_("Create", inParams);
|
|
||||||
return outParams.ProcessId;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getEnvString = function(envName) {
|
exports.getEnvString = function(envName) {
|
||||||
|
|
60
lib/wmi.js
60
lib/wmi.js
|
@ -2,7 +2,59 @@
|
||||||
// WMI(Windows Management Instrumentation) API
|
// WMI(Windows Management Instrumentation) API
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
var WMIObject = function() {
|
var WMIClassObject = function() {
|
||||||
|
this.interface = new WMIObject();
|
||||||
|
this.class = null;
|
||||||
|
this.className = "";
|
||||||
|
this.method = null;
|
||||||
|
this.methodName = "";
|
||||||
|
this.inParams = {};
|
||||||
|
this.outParams = {};
|
||||||
|
|
||||||
|
this.setClass = function(className) {
|
||||||
|
this.className = className;
|
||||||
|
this.class = this.interface.Get(className);
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
this.create = function() {
|
||||||
|
var si = this.class.SpawnInstance_();
|
||||||
|
return si;
|
||||||
|
};
|
||||||
|
this.setMethod = function(methodName) {
|
||||||
|
this.methodName = methodName;
|
||||||
|
this.method = this.class.Methods_.Item(methodName);
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
this.setParameter = function(key, value) {
|
||||||
|
this.inParams[key] = value;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
this.setParameters = function(params) {
|
||||||
|
if (typeof(params) !== "undefined") {
|
||||||
|
for (k in params) {
|
||||||
|
this.setParameter(k, params[k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
this.execute = function() {
|
||||||
|
var params = this.method.InParameters.SpawnInstance_();
|
||||||
|
for (k in this.parameters) {
|
||||||
|
params[k] = this.inParams[k];
|
||||||
|
}
|
||||||
|
this.outParams = this.class.ExecMethod_(this.methodName, params);
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
this.get = function(key) {
|
||||||
|
if (key in this.outParams) {
|
||||||
|
return this.outParams[key];
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
var WMIQueryObject = function() {
|
||||||
var wbemFlagReturnImmediately = 0x10;
|
var wbemFlagReturnImmediately = 0x10;
|
||||||
var wbemFlagForwardOnly = 0x20;
|
var wbemFlagForwardOnly = 0x20;
|
||||||
|
|
||||||
|
@ -64,7 +116,11 @@ var WMIObject = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.execQuery = function(query) {
|
exports.execQuery = function(query) {
|
||||||
return (new WMIObject()).execQuery(query);
|
return (new WMIQueryObject()).execQuery(query);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.setClass = function(className) {
|
||||||
|
return (new WMIClassObject()).setClass(className);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.VERSIONINFO = "WMI interface (wmi.js) version 0.1";
|
exports.VERSIONINFO = "WMI interface (wmi.js) version 0.1";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user