CODE/2022-10-27

Registering Programs as Windows Services

Windows Service Control Manager (SCM) manages services that implement the Windows service interface. You can register and inspect a service with sc.exe, but an arbitrary batch file or desktop executable is not automatically a valid service.

Register a service executable

Run Command Prompt as Administrator and supply the full path to an executable designed to run as a Windows service:
shell_snippet
Shell · 1 line|
sc.exe create MyService binPath= "C:\Services\MyService.exe" start= auto
The space after binPath= and start= is required by sc.exe. Quote paths containing spaces. start= auto configures automatic startup; use start= demand for manual startup.

Start, inspect, and stop

shell_snippet
Shell · 4 lines|
sc.exe start MyService
sc.exe query MyService
sc.exe qc MyService
sc.exe stop MyService
query shows current status; qc shows the configured executable, startup type, and service account. If startup fails, inspect the service's logs and Windows Event Viewer.

Remove the registration

shell_snippet
Shell · 2 lines|
sc.exe stop MyService
sc.exe delete MyService
Deletion removes the service registration, not the application files. A service may remain marked for deletion until open handles are closed.

What about batch files and ordinary programs?

Do not point binPath directly at a .bat file or use cmd.exe /c start and assume SCM can control it. Use a service-aware wrapper or implement the Windows service interface, and configure its shutdown, working directory, account, and logging. For a task that only needs to run on a schedule or at sign-in, Task Scheduler may be a better fit.
Service changes generally require administrator privileges. Test under the intended service account and grant it only the access it needs.
COMPANION ESSAYS / 思想脉络与互照篇目
同卷深读2026-05-22 ·

Installing Python 3 Alongside System Python on CentOS 7

同属「系统工程卷」脉络衍生思考与工程推演推演阅读 →
跨界互照2026-08-22 ·

我的书架:03|金融经管:经济运行、金融体系与企业治理

我的书架:03|金融经管:经济运行、金融体系与企业治理

跨领域对照思辨 · 从「思想随笔」视界互为印证推演阅读 →
RELATED INDEX / 相关阅读索引
柯航hang.ke·© 2014—2026
CC BY-NC 4.0·