mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-06 06:54:58 +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) {
|
||||
var SW_HIDE = 0;
|
||||
var pid = 0;
|
||||
|
||||
var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2")
|
||||
var si = wmi.Get("Win32_ProcessStartup").SpawnInstance_();
|
||||
var si = WMI.setClass("Win32_ProcessStartup").create();
|
||||
si.ShowWindow = SW_HIDE;
|
||||
si.CreateFlags = 16777216;
|
||||
si.X = si.Y = si.XSize = si.ySize = 1;
|
||||
|
||||
//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");
|
||||
var inParams = method.InParameters.SpawnInstance_();
|
||||
inParams.CommandLine = cmd;
|
||||
inParams.CurrentDirectory = null;
|
||||
inParams.ProcessStartupInformation = si;
|
||||
|
||||
var outParams = w32proc.ExecMethod_("Create", inParams);
|
||||
return outParams.ProcessId;
|
||||
return process.get("ProcessID");
|
||||
};
|
||||
|
||||
exports.getEnvString = function(envName) {
|
||||
|
|
60
lib/wmi.js
60
lib/wmi.js
|
@ -2,7 +2,59 @@
|
|||
// 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 wbemFlagForwardOnly = 0x20;
|
||||
|
||||
|
@ -64,7 +116,11 @@ var WMIObject = function() {
|
|||
};
|
||||
|
||||
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";
|
||||
|
|
Loading…
Reference in New Issue
Block a user