report service name in console
Massimo Melina committed
Dec 19, 2024 at 11:04 UTC
7134ffc4c434a5863a2f9c574c853ce4b4fddebf
1 file changed
+5
-3
src/util-os.ts
+5
-3
@@ -70,16 +70,18 @@ export async function runCmd(cmd: string, args: string[] = [], options: ExecOpti
70
return (stderr || stdout).replace(/\r/g, '')
71
}
72
73
+// returns pid-to-name object
74
async function getWindowsServicePids() {
75
const res = await runCmd('tasklist /svc /fo csv')
76
const parsed = new Parser().parse(res)
77
const no = parsed?.[1]?.[2]
77
- return parsed.slice(2).filter(x => x[2] !== no).map(x => Number(x[1]))
78
+ return Object.fromEntries(parsed.slice(2).filter(x => x[2] !== no).map(x => [x[1], x[2]]))
79
}
80
81
export const RUNNING_AS_SERVICE = IS_WINDOWS && getWindowsServicePids().then(x => {
81
- const ret = x.includes(pid) || x.includes(ppid)
82
- if (ret) console.log("running as service")
82
+ const ret = x[pid] || x[ppid]
83
+ if (ret)
84
+ console.log("running as service", ret)
85
return ret
86
}, e => {
87
console.log("couldn't determine if we are running as a service")