Skip to content

Commit

Permalink
Fix windows auto-start
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon committed Nov 19, 2024
1 parent b0bf35e commit df881f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cross/service",
"version": "1.0.5",
"version": "1.0.6",
"fmt": {
"lineWidth": 200
},
Expand Down
17 changes: 17 additions & 0 deletions lib/managers/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit df881f0

Please sign in to comment.