mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-12-15 15:19:59 +08:00
win自动化分类添加进程管理、注册表管理、服务管理、软件管理和系统工具
This commit is contained in:
39
plugin/lib/quickcomposer/windows/service.js
Normal file
39
plugin/lib/quickcomposer/windows/service.js
Normal 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,
|
||||
};
|
||||
Reference in New Issue
Block a user