From df881f097599641761613c4a89e57d73c5b5f71d Mon Sep 17 00:00:00 2001 From: Hexagon Date: Tue, 19 Nov 2024 21:09:09 +0100 Subject: [PATCH] Fix windows auto-start --- deno.json | 2 +- lib/managers/windows.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/deno.json b/deno.json index 659e092..879f6aa 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@cross/service", - "version": "1.0.5", + "version": "1.0.6", "fmt": { "lineWidth": 200 }, diff --git a/lib/managers/windows.ts b/lib/managers/windows.ts index e53929d..daced90 100644 --- a/lib/managers/windows.ts +++ b/lib/managers/windows.ts @@ -62,11 +62,28 @@ class WindowsService { "-Verb", "RunAs", ]; + // Try to install the service const installService = await spawn(psAndArgs); if (installService.code !== 0) { await this.rollback(serviceBatchPath); throw new Error("Failed to install service. Error: \n" + installService.stdout + installService.stderr); } + // Force start the service + const startArgs = `start ${config.name}`; + const startService = await spawn([ + "powershell.exe", + "-Command", + "Start-Process", + "sc.exe", + "-ArgumentList", + `'${startArgs}'`, + "-Verb", + "RunAs", + ]); + if (startService.code !== 0) { + await this.rollback(serviceBatchPath); + throw new Error(`Failed to start service. Error: \n${startService.stderr}`); + } return { servicePath: serviceBatchPath, serviceFileContent: batchFileContent,