mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-03-12 08:55:14 +00:00
154 lines
4.4 KiB
JavaScript
154 lines
4.4 KiB
JavaScript
////////////////////////////////////////////////////////////////////////
|
|
// System API
|
|
////////////////////////////////////////////////////////////////////////
|
|
var SHELL = require("lib/shell");
|
|
var WSH = CreateObject("WScript.Shell");
|
|
var WMI = require("lib/wmi");
|
|
|
|
exports.VERSIONINFO = "System Module (system.js) version 0.1";
|
|
exports.global = global;
|
|
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_();
|
|
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 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;
|
|
};
|
|
|
|
exports.getEnvString = function(envName) {
|
|
return WSH.ExpandEnvironmentStrings('%' + envName + '%');
|
|
};
|
|
|
|
exports.get32BitFolder = function() {
|
|
var base = exports.getEnvString("WINDIR");
|
|
var syswow64 = base + "\\SysWOW64\\";
|
|
|
|
if (JPTUDBSTOW.FS.FolderExists(syswow64))
|
|
return syswow64;
|
|
|
|
return base + "\\System32\\";
|
|
}
|
|
|
|
exports.isElevated = function() {
|
|
try {
|
|
WSH.RegRead("HKEY_USERS\\s-1-5-19\\");
|
|
return true;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
exports.getOS = function() {
|
|
return WMI.execQuery("SELECT * FROM Win32_OperatingSystem").fetch().get("Caption").rtrim();
|
|
};
|
|
|
|
exports.getDCName = function() {
|
|
try {
|
|
var DC = WSH.RegRead("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\History\\DCName");
|
|
if (DC.length > 0)
|
|
return DC;
|
|
} catch (e) {}
|
|
};
|
|
|
|
exports.getArch = function() {
|
|
return WMI.execQuery("SELECT * FROM Win32_OperatingSystem").fetch().get("OSArchitecture");
|
|
};
|
|
|
|
exports.getUUID = function() {
|
|
return WMI.execQuery("SELECT * FROM Win32_ComputerSystemProduct").fetch().get("UUID").toLowerCase();
|
|
};
|
|
|
|
exports.getCurrentWorkingDirectory = function() {
|
|
try {
|
|
cwd = SHELL.exec("cd", "cwd.txt").rtrim();
|
|
return cwd;
|
|
} catch (e) {}
|
|
};
|
|
|
|
exports.getDirName = function(path) {
|
|
var delimiter = "\\";
|
|
var pos = path.lastIndexOf(delimiter);
|
|
return (pos > -1 ? path.substring(0, pos) : "");
|
|
};
|
|
|
|
exports.getFileName = function(path) {
|
|
var delimiter = "\\";
|
|
var pos = path.lastIndexOf(delimiter);
|
|
return (pos > -1 ? path.substring(pos + delimiter.length) : "");
|
|
};
|
|
|
|
exports.getCurrentScriptDirectory = function() {
|
|
if (typeof(WScript) !== "undefined") {
|
|
return exports.getDirName(WScript.ScriptFullName);
|
|
} else if (typeof(document) !== "undefined") {
|
|
return exports.getDirName(document.location.pathname);
|
|
} else {
|
|
return ".";
|
|
}
|
|
};
|
|
|
|
exports.getCurrentScriptName = function() {
|
|
if (typeof(WScript) !== "undefined") {
|
|
return WScript.ScriptName;
|
|
} else if (typeof(document) !== "undefined") {
|
|
return exports.getFileName(document.location.pathname);
|
|
} else {
|
|
return "";
|
|
}
|
|
};
|
|
|
|
exports.getNetworkInterfaces = function() {
|
|
return WMI.execQuery("SELECT * FROM Win32_NetworkAdapterConfiguration").fetchAll();
|
|
};
|
|
|
|
exports.getProcesses = function() {
|
|
return WMI.execQuery("Select * From Win32_Process").fetchAll();
|
|
};
|
|
|
|
exports.killProcess = function(pid) {
|
|
var processes = exports.getProcesses();
|
|
|
|
for (var i = 0; i < processes.length; i++) {
|
|
try {
|
|
if (processes[i].ProcessId == pid) {
|
|
processes[i].Terminate();
|
|
return true;
|
|
}
|
|
} catch (e) {}
|
|
}
|
|
|
|
return false;
|
|
};
|
|
|
|
exports.createShortcut = function(shoutcutName, fileName) {
|
|
var workingDirectory = exports.getCurrentWorkingDirectory();
|
|
var desktopPath = WSH.SpecialFolders("Desktop");
|
|
var link = WSH.CreateShortcut(desktopPath + "\\" + shoutcutName + ".lnk");
|
|
link.IconLocation = fileName + ",1";
|
|
link.TargetPath = workingDirectory + "\\" + fileName;
|
|
link.WindowStyle = 3;
|
|
link.WorkingDirectory = workingDirectory;
|
|
link.Save();
|
|
};
|
|
|
|
exports.ping = function(address) {
|
|
return WMI.execQuery("Select * From Win32_PingStatus where address='" + address + "'").fetch().get("ResponseTime");
|
|
};
|