win自动化分类添加进程管理、注册表管理、服务管理、软件管理和系统工具

This commit is contained in:
fofolee
2025-01-14 16:24:12 +08:00
parent ab5f90ea51
commit 64e231d5cb
12 changed files with 2593 additions and 0 deletions

View File

@@ -1,9 +1,19 @@
const window = require("./window");
const sendmessage = require("./sendmessage");
const monitor = require("./monitor");
const process = require("./process");
const registry = require("./registry");
const service = require("./service");
const software = require("./software");
const utils = require("./utils");
module.exports = {
window,
sendmessage,
monitor,
process,
registry,
service,
software,
utils,
};

View File

@@ -0,0 +1,57 @@
const { runCsharpFeature } = require("../../csharp");
/**
* 列出进程
* @returns {Array} 进程列表
*/
const listProcesses = async function () {
const args = ["-type", "list"];
const result = await runCsharpFeature("process", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
try {
return JSON.parse(result);
} catch (error) {
console.error("解析进程列表失败:", error);
return null;
}
};
/**
* 终止进程
* @param {string} target 进程ID或名称
* @returns {boolean} 是否成功
*/
const killProcess = async function (target) {
const args = ["-type", "kill", "-target", target];
const result = await runCsharpFeature("process", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
return true;
};
/**
* 启动进程
* @param {string} path 程序路径
* @param {string} arguments 启动参数
* @returns {boolean} 是否成功
*/
const startProcess = async function (path, arguments = "") {
const args = ["-type", "start", "-path", path];
if (arguments) {
args.push("-args", arguments);
}
const result = await runCsharpFeature("process", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
return true;
};
module.exports = {
listProcesses,
killProcess,
startProcess,
};

View File

@@ -0,0 +1,96 @@
const { runCsharpFeature } = require("../../csharp");
/**
* 获取注册表值
* @param {string} path 注册表路径
* @param {string} name 值名称
* @returns {object} 注册表值
*/
const getValue = async function (path, name = "") {
const args = ["-type", "get", "-path", path];
if (name) {
args.push("-name", name);
}
const result = await runCsharpFeature("registry", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
try {
return JSON.parse(result);
} catch (error) {
console.error("解析注册表值失败:", error);
return null;
}
};
/**
* 设置注册表值
* @param {string} path 注册表路径
* @param {string} name 值名称
* @param {string} value 值
* @param {string} valueType 值类型
* @returns {boolean} 是否成功
*/
const setValue = async function (path, name, value, valueType = "string") {
const args = [
"-type",
"set",
"-path",
path,
"-name",
name,
"-value",
value,
"-valuetype",
valueType,
];
const result = await runCsharpFeature("registry", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
return true;
};
/**
* 删除注册表值
* @param {string} path 注册表路径
* @param {string} name 值名称
* @returns {boolean} 是否成功
*/
const deleteValue = async function (path, name = "") {
const args = ["-type", "delete", "-path", path];
if (name) {
args.push("-name", name);
}
const result = await runCsharpFeature("registry", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
return true;
};
/**
* 列出注册表项
* @param {string} path 注册表路径
* @returns {Array} 注册表项列表
*/
const listKeys = async function (path) {
const args = ["-type", "list", "-path", path];
const result = await runCsharpFeature("registry", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
try {
return JSON.parse(result);
} catch (error) {
console.error("解析注册表项列表失败:", error);
return null;
}
};
module.exports = {
getValue,
setValue,
deleteValue,
listKeys,
};

View File

@@ -0,0 +1,39 @@
const { runCsharpFeature } = require("../../csharp");
/**
* 列出服务
* @returns {Array} 服务列表
*/
const listServices = async function () {
const args = ["-type", "list"];
const result = await runCsharpFeature("service", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
try {
return JSON.parse(result);
} catch (error) {
console.error("解析服务列表失败:", error);
return null;
}
};
/**
* 控制服务
* @param {string} name 服务名称
* @param {string} operation 操作类型start/stop/pause/continue
* @returns {boolean} 是否成功
*/
const controlService = async function (name, operation) {
const args = ["-type", operation, "-name", name];
const result = await runCsharpFeature("service", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
return true;
};
module.exports = {
listServices,
controlService,
};

View File

@@ -0,0 +1,38 @@
const { runCsharpFeature } = require("../../csharp");
/**
* 列出已安装软件
* @returns {Array} 软件列表
*/
const listSoftware = async function () {
const args = ["-type", "list"];
const result = await runCsharpFeature("software", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
try {
return JSON.parse(result);
} catch (error) {
console.error("解析软件列表失败:", error);
return null;
}
};
/**
* 卸载软件
* @param {string} target 软件ID
* @returns {boolean} 是否成功
*/
const uninstallSoftware = async function (target) {
const args = ["-type", "uninstall", "-target", target];
const result = await runCsharpFeature("software", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
return true;
};
module.exports = {
listSoftware,
uninstallSoftware,
};

View File

@@ -0,0 +1,146 @@
const { runCsharpFeature } = require("../../csharp");
/**
* 设置壁纸
* @param {string} path 壁纸路径
* @returns {boolean} 是否成功
*/
const setWallpaper = async function (path) {
const args = ["-type", "wallpaper", "-path", path];
const result = await runCsharpFeature("utils", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
return true;
};
/**
* 控制显示器
* @param {string} action 动作on/off
* @returns {boolean} 是否成功
*/
const controlMonitor = async function (action) {
const args = ["-type", "monitor", "-action", action];
const result = await runCsharpFeature("utils", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
return true;
};
/**
* 电源控制
* @param {string} mode 模式sleep/hibernate/awake/normal
* @returns {boolean} 是否成功
*/
const powerControl = async function (mode) {
const args = ["-type", "power", "-mode", mode];
const result = await runCsharpFeature("utils", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
return true;
};
/**
* 配置网络
* @param {string} interfaceName 网卡名称
* @param {string} ip IP地址
* @param {string} mask 子网掩码
* @param {string} gateway 网关
* @param {string} dns DNS服务器
* @returns {boolean} 是否成功
*/
const configureNetwork = async function (
interfaceName,
ip,
mask,
gateway = "",
dns = ""
) {
const args = [
"-type",
"network",
"-interface",
interfaceName,
"-ip",
ip,
"-mask",
mask,
];
if (gateway) args.push("-gateway", gateway);
if (dns) args.push("-dns", dns);
const result = await runCsharpFeature("utils", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
return true;
};
/**
* 管理开机启动项
* @param {string} path 程序路径
* @param {string} name 启动项名称
* @param {boolean} remove 是否移除
* @returns {boolean} 是否成功
*/
const manageStartup = async function (path, name, remove = false) {
const args = ["-type", "startup", "-path", path, "-name", name];
if (remove) args.push("-remove");
const result = await runCsharpFeature("utils", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
return true;
};
/**
* 创建快捷方式
* @param {string} targetPath 目标路径
* @param {string} shortcutPath 快捷方式路径
* @param {string} args 启动参数
* @returns {boolean} 是否成功
*/
const createShortcut = async function (targetPath, shortcutPath, args = "") {
const cmdArgs = [
"-type",
"shortcut",
"-target",
targetPath,
"-path",
shortcutPath,
];
if (args) cmdArgs.push("-args", args);
const result = await runCsharpFeature("utils", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
return true;
};
/**
* 设置亮度
* @param {number} level 亮度级别(0-100)
* @returns {boolean} 是否成功
*/
const setBrightness = async function (level) {
const args = ["-type", "brightness", "-level", level.toString()];
const result = await runCsharpFeature("utils", args);
if (result && result.startsWith("Error:")) {
throw new Error(result.substring(7));
}
return true;
};
module.exports = {
setWallpaper,
controlMonitor,
powerControl,
configureNetwork,
manageStartup,
createShortcut,
setBrightness,
};