Update winservice.js

This commit is contained in:
Namhyeon Go 2021-06-20 06:41:48 +09:00 committed by GitHub
parent 7d49122aee
commit fe8867953c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,118 +1,35 @@
////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////
// Windows Service API // VirtualInput API
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
var SHELL = require("lib/shell");
exports.VERSIONINFO = "Windows Service Lib (service.js) version 0.1"; var VirtualInputObject = function() {
this.oShell = null;
this.oAutoIt = null;
this.create = function() {
try {
this.oShell = CreateObject("WScript.Shell");
this.oAutoIt = CreateObject("AutoItX.Control");
} catch (e) {
console.error("VirtualInputObject.create() -> " + e.message);
}
);
this.moveMouse = function(x, y) {
this.oAutoIt.MouseMove(x, y);
};
this.sendKeys = function(s) {
this.oShell.SendKeys(s);
};
this.create();
};
exports.VERSIONINFO = "VirtualInput Lib (virtualinput.js) version 0.1";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;
// https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/dd228922(v=ws.11) exports.create = function() {
exports.queryService = function(name, options) { return new VirtualInputObject();
var cmd = [
"sc",
"query",
name
],
_options = {
type: [
"service", // type= {driver | service | all}
"own" // type= {own | share | interact | kernel | filesys | rec | adapt}
],
state: "active", // state= {active | inactive | all}
bufsize: "1024", // bufsize= <BufferSize>
ri: "0", // ri= <ResumeIndex>
group: "" // group= <GroupName>
};
for (var k in _options) {
if (k in options) {
_options[k] = options[k];
}
if (_options[k] !== false) {
if (Array.isArray(_options[k])) {
for (var i in options[k]) {
cmd.push(k + '=');
cmd.push(_options[k][i]);
}
} else {
cmd.push(k + '=');
cmd.push(_options[k]);
}
}
}
return SHELL.exec(cmd);
};
// https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/sc-create
exports.createService = function(name, options) {
var cmd = [
"sc",
"create",
name
],
_options = {
type: "share", // type= {own | share | kernel | filesys | rec | interact type= {own | share}}
start: "demand", // start= {boot | system | auto | demand | disabled | delayed-auto }
error: "normal", // error= {normal | severe | critical | ignore}
binPath: false, // binpath= <BinaryPathName>
group: false, // group= <LoadOrderGroup>
tag: false, // tag= {yes | no}
depend: false, // depend= <dependencies>
obj: false, // obj= {<AccountName> | <ObjectName>}
DisplayName: false, // displayname= <DisplayName>
password: false // password= <Password>
};
for (var k in _options) {
if (k in options) {
_options[k] = options[k];
}
if (_options[k] !== false) {
if (Array.isArray(_options[k])) {
for (var i in options[k]) {
cmd.push(k + '=');
cmd.push(_options[k][i]);
}
} else {
cmd.push(k + '=');
cmd.push(_options[k]);
}
}
}
return SHELL.exec(cmd);
};
exports.startService = function(name, args) {
var cmd = [
"sc",
"start",
name
];
if (typeof(args) !== "undefined") {
cmd = cmd.concat(args);
}
return SHELL.exec(cmd);
};
exports.stopService = function(name) {
return SHELL.exec([
"sc",
"stop",
name
]);
};
exports.deleteService = function(name) {
return SHELL.exec([
"sc",
"delete",
name
]);
}; };