2023-12-11 07:54:21 +00:00
|
|
|
// lib/system.js
|
|
|
|
// https://github.com/gnh1201/welsonjs
|
2020-07-18 22:52:32 +00:00
|
|
|
var SHELL = require("lib/shell");
|
2020-11-14 19:21:51 +00:00
|
|
|
var WMI = require("lib/wmi");
|
2020-07-07 17:06:38 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function createProcess(cmd) {
|
2020-07-21 06:30:18 +00:00
|
|
|
var SW_HIDE = 0;
|
|
|
|
//wmi.Get("Win32_Process").Create(cmd, null, si, pid);
|
2020-11-14 20:49:28 +00:00
|
|
|
return WMI.setClass("Win32_Process").setMethod("Create").setParameters({
|
2020-11-14 20:35:53 +00:00
|
|
|
"CommandLine": cmd,
|
|
|
|
"CurrentDirectory": null,
|
2020-11-14 20:49:28 +00:00
|
|
|
"ProcessStartupInformation": WMI.setClass("Win32_ProcessStartup").create()
|
|
|
|
.setAttribute("ShowWindow", SW_HIDE)
|
|
|
|
.setAttribute("CreateFlags", 16777216)
|
|
|
|
.setAttribute("X", 1)
|
|
|
|
.setAttribute("Y", 1)
|
|
|
|
.setAttribute("xSize", 1)
|
|
|
|
.setAttribute("ySize", 1)
|
|
|
|
.getInstance()
|
|
|
|
}).execute().get("ProcessID");
|
2023-12-11 07:54:21 +00:00
|
|
|
}
|
2020-07-21 06:30:18 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function getEnvString(envName) {
|
|
|
|
var WSH = CreateObject("WScript.Shell");
|
2023-10-30 18:13:02 +00:00
|
|
|
return (function(s) {
|
2023-11-27 10:14:11 +00:00
|
|
|
switch(s) {
|
|
|
|
case "PROGRAMFILES":
|
|
|
|
return WSH.ExpandEnvironmentStrings("%HOMEDRIVE%\\Program Files");
|
|
|
|
case "PROGRAMFILES(X86)":
|
|
|
|
return WSH.ExpandEnvironmentStrings("%HOMEDRIVE%\\Program Files (x86)");
|
|
|
|
default:
|
|
|
|
return WSH.ExpandEnvironmentStrings('%' + s + '%');
|
|
|
|
}
|
|
|
|
})(envName.toUpperCase());
|
2023-12-11 07:54:21 +00:00
|
|
|
}
|
2020-07-21 06:30:18 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function get32BitFolder() {
|
|
|
|
var base = getEnvString("WINDIR");
|
2020-07-21 06:30:18 +00:00
|
|
|
var syswow64 = base + "\\SysWOW64\\";
|
|
|
|
|
2023-10-24 02:13:19 +00:00
|
|
|
if (CreateObject("Scripting.FileSystemObject").FolderExists(syswow64))
|
2020-07-21 06:30:18 +00:00
|
|
|
return syswow64;
|
|
|
|
|
|
|
|
return base + "\\System32\\";
|
|
|
|
}
|
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function isElevated() {
|
|
|
|
var WSH = CreateObject("WScript.Shell");
|
2020-07-07 17:06:38 +00:00
|
|
|
try {
|
|
|
|
WSH.RegRead("HKEY_USERS\\s-1-5-19\\");
|
|
|
|
return true;
|
2023-12-11 07:54:21 +00:00
|
|
|
} catch (e) {}
|
2020-07-07 17:06:38 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getOS() {
|
2023-10-30 18:13:02 +00:00
|
|
|
return WMI.execQuery("SELECT Caption FROM Win32_OperatingSystem").fetch().get("Caption").trim();
|
2023-12-11 07:54:21 +00:00
|
|
|
}
|
2020-07-07 17:06:38 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function getDCName() {
|
|
|
|
var WSH = CreateObject("WScript.Shell");
|
2020-07-07 17:06:38 +00:00
|
|
|
try {
|
|
|
|
var DC = WSH.RegRead("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\History\\DCName");
|
|
|
|
if (DC.length > 0)
|
|
|
|
return DC;
|
|
|
|
} catch (e) {}
|
2023-12-11 07:54:21 +00:00
|
|
|
}
|
2020-07-07 17:06:38 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function getArch() {
|
2023-10-30 18:13:02 +00:00
|
|
|
return WMI.execQuery("SELECT OSArchitecture FROM Win32_OperatingSystem").fetch().get("OSArchitecture");
|
2023-12-11 07:54:21 +00:00
|
|
|
}
|
2020-07-07 17:06:38 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function getUUID() {
|
2023-10-30 18:13:02 +00:00
|
|
|
return WMI.execQuery("SELECT UUID FROM Win32_ComputerSystemProduct").fetch().get("UUID").toLowerCase();
|
2023-12-11 07:54:21 +00:00
|
|
|
}
|
2020-07-07 17:06:38 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function getCurrentWorkingDirectory() {
|
2020-07-07 17:06:38 +00:00
|
|
|
try {
|
2023-12-11 07:54:21 +00:00
|
|
|
return SHELL.exec("cd").trim();
|
2020-07-07 17:06:38 +00:00
|
|
|
} catch (e) {}
|
2023-12-11 07:54:21 +00:00
|
|
|
}
|
2020-07-07 17:06:38 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function getDirName(path) {
|
|
|
|
var pos = Math.max.apply(null, [path.lastIndexOf("\\"), path.lastIndexOf("/")]);
|
2020-08-05 07:35:43 +00:00
|
|
|
return (pos > -1 ? path.substring(0, pos) : "");
|
2023-12-11 07:54:21 +00:00
|
|
|
}
|
2020-08-05 07:35:43 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function getFileName(path) {
|
|
|
|
var pos = Math.max.apply(null, [path.lastIndexOf("\\"), path.lastIndexOf("/")]);
|
|
|
|
return (pos > -1 ? path.substring(pos + 1) : "");
|
|
|
|
}
|
2020-08-05 07:35:43 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function getCurrentScriptDirectory() {
|
2020-08-05 07:35:43 +00:00
|
|
|
if (typeof(WScript) !== "undefined") {
|
2023-12-11 07:54:21 +00:00
|
|
|
return getDirName(WScript.ScriptFullName);
|
2020-08-05 07:35:43 +00:00
|
|
|
} else if (typeof(document) !== "undefined") {
|
2023-12-11 07:54:21 +00:00
|
|
|
return getDirName(document.location.pathname);
|
2020-07-21 09:01:38 +00:00
|
|
|
} else {
|
|
|
|
return ".";
|
|
|
|
}
|
2023-12-11 07:54:21 +00:00
|
|
|
}
|
2020-07-07 17:06:38 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function getCurrentScriptName() {
|
2020-11-04 07:30:52 +00:00
|
|
|
if (typeof(WScript) !== "undefined") {
|
2020-07-23 02:05:57 +00:00
|
|
|
return WScript.ScriptName;
|
2020-08-05 07:35:43 +00:00
|
|
|
} else if (typeof(document) !== "undefined") {
|
2023-12-11 07:54:21 +00:00
|
|
|
return getFileName(document.location.pathname);
|
2020-07-23 02:05:57 +00:00
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
2023-12-11 07:54:21 +00:00
|
|
|
}
|
2020-07-23 02:05:57 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function getNetworkInterfaces() {
|
2020-11-14 19:21:51 +00:00
|
|
|
return WMI.execQuery("SELECT * FROM Win32_NetworkAdapterConfiguration").fetchAll();
|
2023-12-11 07:54:21 +00:00
|
|
|
}
|
2020-07-07 17:06:38 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function getProcessList() {
|
|
|
|
return WMI.execQuery("SELECT * FROM Win32_Process").fetchAll();
|
|
|
|
}
|
2020-11-13 08:44:58 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function getPIDList() {
|
|
|
|
return processes.map(function(x) {
|
|
|
|
return x.ProcessID;
|
|
|
|
});
|
|
|
|
}
|
2020-11-27 06:58:43 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function isAlivePID(pid) {
|
2020-11-27 13:31:51 +00:00
|
|
|
if (!pid) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2023-12-11 07:54:21 +00:00
|
|
|
return (getPIDList().indexOf(pid) > -1);
|
2020-11-27 13:31:51 +00:00
|
|
|
}
|
2023-12-11 07:54:21 +00:00
|
|
|
}
|
2020-11-27 13:31:51 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function getProcessListByName(name) {
|
|
|
|
return getProcessList().filter(function(x) {
|
|
|
|
return (x.Caption === name);
|
2020-11-27 13:31:51 +00:00
|
|
|
});
|
2023-12-11 07:54:21 +00:00
|
|
|
}
|
2020-11-15 04:31:35 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function killProcess(pid) {
|
|
|
|
var processes = getProcessList();
|
2020-07-21 06:30:18 +00:00
|
|
|
|
2020-11-13 09:47:03 +00:00
|
|
|
for (var i = 0; i < processes.length; i++) {
|
2020-07-21 06:30:18 +00:00
|
|
|
try {
|
2020-11-13 09:47:03 +00:00
|
|
|
if (processes[i].ProcessId == pid) {
|
|
|
|
processes[i].Terminate();
|
2020-07-21 06:30:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-11-27 06:58:43 +00:00
|
|
|
} catch (e) {
|
2023-12-11 07:54:21 +00:00
|
|
|
console.error("Failed to kill process: ", e.message);
|
2020-11-27 06:58:43 +00:00
|
|
|
}
|
2020-07-07 17:16:41 +00:00
|
|
|
}
|
|
|
|
|
2020-07-21 06:30:18 +00:00
|
|
|
return false;
|
2023-12-11 07:54:21 +00:00
|
|
|
}
|
2020-07-07 17:16:41 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
function createShortcut(shoutcutName, fileName) {
|
|
|
|
var WSH = CreateObject("WScript.Shell");
|
|
|
|
var workingDirectory = getCurrentWorkingDirectory();
|
2020-07-18 22:52:32 +00:00
|
|
|
var desktopPath = WSH.SpecialFolders("Desktop");
|
|
|
|
var link = WSH.CreateShortcut(desktopPath + "\\" + shoutcutName + ".lnk");
|
|
|
|
link.IconLocation = fileName + ",1";
|
|
|
|
link.TargetPath = workingDirectory + "\\" + fileName;
|
2020-11-20 08:44:50 +00:00
|
|
|
link.WindowStyle = 1;
|
2020-07-18 22:52:32 +00:00
|
|
|
link.WorkingDirectory = workingDirectory;
|
|
|
|
link.Save();
|
2023-12-11 07:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ping(address) {
|
|
|
|
return WMI.execQuery("SELECT ResponseTime FROM Win32_PingStatus WHERE address='" + address + "'").fetch().get("ResponseTime");
|
|
|
|
}
|
|
|
|
|
|
|
|
function getProcessVersion() {
|
|
|
|
var getIEVersion = function() {
|
|
|
|
var rv = -1;
|
|
|
|
if (navigator.appName == 'Microsoft Internet Explorer') {
|
|
|
|
var ua = navigator.userAgent;
|
|
|
|
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
|
|
|
|
if (re.exec(ua) != null)
|
|
|
|
rv = parseFloat( RegExp.$1 );
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2020-11-05 06:38:51 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
if (typeof WScript !== "undefined") {
|
|
|
|
return "Microsoft JScript" + (' ' + WScript.Version);
|
|
|
|
} else if (typeof navigator !== "undefined") {
|
|
|
|
return (function(rv) {
|
|
|
|
return "MSIE" + (rv < 0 ? '' : (' ' + rv));
|
|
|
|
})(getIEVersion());
|
|
|
|
}
|
|
|
|
}
|
2023-10-30 18:13:02 +00:00
|
|
|
|
2023-12-11 07:54:21 +00:00
|
|
|
exports.createProcess = createProcess;
|
|
|
|
exports.getEnvString = getEnvString;
|
|
|
|
exports.get32BitFolder = get32BitFolder;
|
|
|
|
exports.isElevated = isElevated;
|
|
|
|
exports.getOS = getOS;
|
|
|
|
exports.getDCName = getDCName;
|
|
|
|
exports.getArch = getArch;
|
|
|
|
exports.getUUID = getUUID;
|
|
|
|
exports.getCurrentWorkingDirectory = getCurrentWorkingDirectory;
|
|
|
|
exports.getDirName = getDirName;
|
|
|
|
exports.getFileName = getFileName;
|
|
|
|
exports.getCurrentScriptDirectory = getCurrentScriptDirectory;
|
|
|
|
exports.getCurrentScriptName = getCurrentScriptName;
|
|
|
|
exports.getNetworkInterfaces = getNetworkInterfaces;
|
|
|
|
exports.getProcessList = getProcessList;
|
|
|
|
exports.getPIDList = getPIDList;
|
|
|
|
exports.isAlivePID = isAlivePID;
|
|
|
|
exports.getProcessListByName = getProcessListByName;
|
|
|
|
exports.killProcess = killProcess;
|
|
|
|
exports.createShortcut = createShortcut;
|
|
|
|
exports.ping = ping;
|
|
|
|
exports.getProcessVersion = getProcessVersion;
|
|
|
|
|
|
|
|
exports.VERSIONINFO = "System Module (system.js) version 0.1.5";
|
2023-10-30 18:13:02 +00:00
|
|
|
exports.global = global;
|
|
|
|
exports.require = global.require;
|