Skip to content

Commit 86e19ce

Browse files
chore: new release with minimal changes
1 parent bd126f4 commit 86e19ce

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

docs/commands.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ Commands:
207207
start Start the Windows Service
208208
stop Stop the Windows Service
209209
status Check Service Status
210+
startup <type> Set Service Startup Type
210211
help [command] display help for command
211212
```
212213

src/commands/service.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Command } from 'commander';
2-
import { installService, uninstallService, startService, stopService, isServiceInstalled, isServiceRunning, updateServiceBinPath } from '../system/service.js';
2+
import { installService, uninstallService, startService, stopService, isServiceInstalled, isServiceRunning, updateServiceBinPath, setServiceStartupType } from '../system/service.js';
33
import { logger } from '../core/logger.js';
44

55
export const serviceCommand = new Command('service')
@@ -95,3 +95,29 @@ serviceCommand.command('status')
9595
process.exit(1);
9696
}
9797
});
98+
99+
serviceCommand.command('startup')
100+
.description('Set Service Startup Type')
101+
.argument('<type>', 'Startup type (automatic, manual, disabled, delayed)')
102+
.action(async (type) => {
103+
const validTypes = ['automatic', 'manual', 'disabled', 'delayed'];
104+
const normalizedType = type.toLowerCase();
105+
106+
if (!validTypes.includes(normalizedType)) {
107+
logger.error(`Invalid startup type. Must be one of: ${validTypes.join(', ')}`);
108+
process.exit(1);
109+
}
110+
111+
try {
112+
const typeMap: Record<string, 'Automatic' | 'Manual' | 'Disabled' | 'Delayed'> = {
113+
'automatic': 'Automatic',
114+
'manual': 'Manual',
115+
'disabled': 'Disabled',
116+
'delayed': 'Delayed'
117+
};
118+
await setServiceStartupType(typeMap[normalizedType]);
119+
} catch (error) {
120+
logger.error('Failed to set startup type', error);
121+
process.exit(1);
122+
}
123+
});

src/system/service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,18 @@ export async function stopService() {
108108
logger.info(`Stopping service ${SERVICE_NAME}...`);
109109
await runPs(`Stop-Service -Name "${SERVICE_NAME}" -Force`);
110110
}
111+
112+
export async function setServiceStartupType(type: 'Automatic' | 'Manual' | 'Disabled' | 'Delayed') {
113+
if (!await isAdmin()) {
114+
throw new Error('Admin privileges required to change service startup type.');
115+
}
116+
117+
if (type === 'Delayed') {
118+
// Delayed start is a special case of Automatic
119+
await runPs(`Set-Service -Name "${SERVICE_NAME}" -StartupType Automatic`);
120+
await runPs(`sc.exe config "${SERVICE_NAME}" start= delayed-auto`);
121+
} else {
122+
await runPs(`Set-Service -Name "${SERVICE_NAME}" -StartupType ${type}`);
123+
}
124+
logger.info(`Service startup type set to ${type}.`);
125+
}

0 commit comments

Comments
 (0)