add extra services information

Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
Simon Smith
2024-01-24 11:51:28 +00:00
committed by GitHub
parent b860981925
commit b1451a1c8a
2 changed files with 88 additions and 23 deletions

View File

@@ -1304,6 +1304,41 @@ function handleServerCommand(data) {
}
break;
}
case 'service': {
// return information about the service
try {
var service = require('service-manager').manager.getService(data.serviceName);
if (service != null) {
var reply = {
name: (service.name ? service.name : ''),
status: (service.status ? service.status : ''),
startType: (service.startType ? service.startType : ''),
failureActions: (service.failureActions ? service.failureActions : ''),
installedDate: (service.installedDate ? service.installedDate : ''),
installedBy: (service.installedBy ? service.installedBy : '') ,
user: (service.user ? service.user : '')
};
if(reply.installedBy.indexOf('S-1-5') != -1) {
var cmd = "(Get-WmiObject -Class win32_userAccount -Filter \"SID='"+service.installedBy+"'\").Caption";
var replydata = "";
var pws = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-'], {});
pws.descriptorMetadata = 'UserSIDPowerShell';
pws.stdout.on('data', function (c) { replydata += c.toString(); });
pws.stderr.on('data', function (c) { replydata += c.toString(); });
pws.stdin.write(cmd + '\r\nexit\r\n');
pws.on('exit', function () {
if (replydata != "") reply.installedBy = replydata;
mesh.SendCommand({ action: 'msg', type: 'service', value: JSON.stringify(reply), sessionid: data.sessionid });
delete pws;
});
} else {
mesh.SendCommand({ action: 'msg', type: 'service', value: JSON.stringify(reply), sessionid: data.sessionid });
}
}
} catch (ex) {
mesh.SendCommand({ action: 'msg', type: 'service', error: ex, sessionid: data.sessionid })
}
}
case 'services': {
// Return the list of installed services
var services = null;