Merge pull request #640 from si458/patch-2

services() speedup windows and incorrect started compare
This commit is contained in:
Sebastian Hildebrandt 2022-01-17 07:02:33 +01:00 committed by GitHub
commit cbdb462f95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -324,7 +324,16 @@ function services(srv, callback) {
}
if (_windows) {
try {
util.powerShell('Get-WmiObject Win32_Service | fl *').then((stdout, error) => {
let wincommand = "Get-WmiObject Win32_Service";
if (srvs[0] !== '*') {
wincommand += ' -Filter "';
for (let i = 0; i < srvs.length; i++) {
wincommand += `Name='${srvs[i]}' or `;
}
wincommand = `${wincommand.slice(0,-4)}"`;
}
wincommand += ' | fl *';
util.powerShell(wincommand).then((stdout, error) => {
if (!error) {
let serviceSections = stdout.split(/\n\s*\n/);
for (let i = 0; i < serviceSections.length; i++) {
@ -338,7 +347,7 @@ function services(srv, callback) {
if (srvString === '*' || srvs.indexOf(srvName) >= 0 || srvs.indexOf(srvCaption) >= 0) {
result.push({
name: srvName,
running: (started === 'TRUE'),
running: (started.toLowerCase() === 'true'),
startmode: startMode,
pids: [pid],
cpu: 0,