mirror of
https://github.com/gnh1201/welsonjs.git
synced 2024-11-26 07:21:43 +00:00
Update winservice.js
This commit is contained in:
parent
7d49122aee
commit
fe8867953c
|
@ -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.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.queryService = function(name, options) {
|
||||
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
|
||||
]);
|
||||
exports.create = function() {
|
||||
return new VirtualInputObject();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user