Skip to content
Latchkey

sc: Manage Windows Services in CI

sc.exe controls the Service Control Manager: create, start, query, and delete services. CI uses it to stand up a dependency (database, broker) as a service during integration tests.

When an integration test needs a background service, sc.exe registers and controls it. Mind the exact key= value spacing syntax, the top tripwire for new users.

What it does

sc talks to the Service Control Manager. create registers a service from an executable path, start/stop control it, query reports state, and delete removes it. The option syntax requires a space after the equals sign: binPath= "C:\app.exe".

Common usage

cmd
:: create (note the space after each '=')
sc create MyService binPath= "C:\app\svc.exe" start= auto

sc start MyService
sc query MyService
sc stop MyService
sc delete MyService

Options

Command / argWhat it does
create <name> binPath= <exe>Register a new service
start= auto|demand|disabledStartup type (note the space after =)
start / stop <name>Start or stop the service
query <name>Show current state (RUNNING/STOPPED)
delete <name>Remove the service registration
config <name> ...Change properties of an existing service

In CI

After sc start, poll sc query until the state is RUNNING before driving tests, since start returns before the service is ready. Always sc stop and sc delete in a cleanup step so a re-run does not hit a leftover service. Service operations require an elevated step.

Common errors in CI

"[SC] OpenService FAILED 1060: The specified service does not exist as an installed service" means a typo in the name or the create failed silently (often the binPath= spacing). "Error 1053: The service did not respond to the start or control request in a timely fashion" means the exe is not a real Windows service or is slow to start. "[SC] OpenSCManager FAILED 5: Access is denied." means the step is not elevated.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →