The Big Picture: The Hotel Manager
In the hotel from Section 1, someone decides who starts work, who is on duty, and what to do when a worker does not turn up. That is the manager. In Windows this manager is the Service Control Manager, or SCM.
You / admin tools / other programs
(services.msc, sc.exe, PowerShell, apps)
│ "start Spooler", "stop W32Time", "what is running?"
▼
┌────────────────────┐
│ SCM (services.exe)│ ◄── reads the service list (registry)
└──────────┬─────────┘
starts / stops / watches
┌───────────┬────┴──────┬───────────┐
▼ ▼ ▼ ▼
Spooler W32Time Dhcp ...hundreds more
2.1 SCM Role (services.exe)
What it is: The SCM is not a separate program you can see by that name. It lives inside the process services.exe, found in C:\Windows\System32. There is always exactly one services.exe running.
How it starts. In Chapter 6 you saw the boot order: the kernel starts, then the Session Manager (smss.exe), then wininit.exe. It is wininit.exe that launches services.exe (along with the security process lsass.exe). So the SCM is one of the first user-mode programs of Windows, and it then starts all the automatic services.
Firmware ─► Boot Manager ─► Kernel ─► smss.exe ─► wininit.exe
├─► services.exe (the SCM)
└─► lsass.exe
services.exe ─► svchost.exe, other service programs
What the SCM does all day:
| Job | Plain meaning |
|---|---|
| Start services at boot | Goes through the list and starts every Automatic one, in the right order (Section 4) |
| Start and stop on request | Obeys a request from you or from a program, if allowed (Section 6) |
| Keep a status | Remembers whether each service is stopped, starting, running and so on |
| Pass control messages | Tells a running service "stop", "pause" or "shut down" |
| Check security | Verifies the caller is allowed to do what they ask |
| Take recovery action | If a service crashes, restarts it or does what the service's recovery settings say (Section 7) |
| Log events | Writes service news to the System event log (Section 8) |
You can see it. In Task Manager, Details tab, find services.exe. It runs under the account SYSTEM. It cannot be ended normally; ending it would crash Windows.
Why does this matter? Because everything about services goes through this one manager, the rules are the same for every service. That makes Windows easier to run and to secure.
2.2 Service Database
What it is: The SCM must know which services exist and how each should run. It keeps this in a service database. On Windows, that database is part of the registry (the settings store you met in Chapter 8).
Where: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
Under it, each service has its own key (folder), named with its service name. For example ...\Services\Spooler.
Inside that key are values (named settings). These are the important ones:
| Value | What it holds | Example |
|---|---|---|
ImagePath | The program file (and options) that runs the service | C:\Windows\System32\spoolsv.exe |
DisplayName | Friendly name | Print Spooler |
Description | One-line explanation | "This service spools print jobs..." |
Start | Startup type, a number (Section 3) | 2 = Automatic |
Type | What kind of service it is | 0x10 own process, 0x20 shared process |
ObjectName | The account it runs under (Section 5) | LocalSystem |
DependOnService | Services that must start first (Section 4) | RPCSS, http |
FailureActions | What to do if it fails (Section 7) | binary data |
ErrorControl | How serious a start failure is for boot | 1 = normal |
Sub-keys. Some services also have a Parameters sub-key (extra settings; for shared services this holds ServiceDll, Section 9) and a Triggers sub-key (Section 3.5).
The word "CurrentControlSet". It is a shortcut. The real data sits in ControlSet001, ControlSet002 and so on, and CurrentControlSet points to the one in use. Always read it through CurrentControlSet.
Read-only look in regedit. Press Win + R, type regedit, press Enter, then go to the path above and click a service. Only look. Do not edit values: a wrong Start or ImagePath can stop Windows booting.
A note about drivers. The same Services area also lists kernel drivers (they have Type values like 1). The SCM and the kernel use it for both. Chapter 13 covers drivers.
Real-world analogy: The service database is the staff roster: every employee, their job, when they start, who they report to, and what to do if they fail to show.
2.3 SCM API (Start/Stop/Query)
What it is: An API (Application Programming Interface) is a set of functions that programs can call to ask Windows to do things. The SCM API is the set of functions to control services. Every tool you use (services.msc, sc, PowerShell, Task Manager) uses it behind the scenes.
The main function families (names from the Windows programming interface, shown so you recognise them):
| Function | Plain meaning |
|---|---|
OpenSCManager | "Let me talk to the manager" |
OpenService | "Give me a handle to this one service" (a handle is a ticket for later requests) |
StartService | Start it |
ControlService | Send a control: stop, pause, continue |
QueryServiceStatus | Ask: is it running? |
QueryServiceConfig | Ask: how is it set up? |
ChangeServiceConfig | Change its settings (startup type and so on) |
CreateService / DeleteService | Install or remove a service |
Your tools, matched to the API:
| Tool | What it does | Needs admin? |
|---|---|---|
services.msc | Windows list with buttons | Viewing: no. Changing: yes |
sc query | Show service state | No |
sc qc <name> | Show a service's configuration | No |
sc start / sc stop | Start or stop | Yes (usually) |
sc config | Change settings | Yes |
Get-Service | PowerShell list | No |
Start-Service, Stop-Service, Set-Service | PowerShell control | Yes (usually) |
Get-CimInstance Win32_Service | Rich details (path, account, PID) | No |
tasklist /svc | Which services live in which process | No |
Try this (safe, read-only):
sc query type= service state= all
sc qc Spooler
Note the strange space: in
sc, the equal sign is stuck to the word and then a space follows:type= service. Without that space the command fails.
Get-Service | Select-Object -First 10
Get-CimInstance Win32_Service -Filter "Name='Spooler'" | Select-Object Name, State, StartMode, StartName, PathName, ProcessIdWhat State can be: Stopped, Running, Paused, or the in-between states Start Pending and Stop Pending (Section 9).
Permission check. Each time a tool opens a service, the SCM checks the caller's identity against the service's security descriptor (Section 6). That is why a normal user can list services but not stop most of them.
Summary
| Concept | Meaning |
|---|---|
| SCM | The service manager, living inside services.exe |
| Launched by | wininit.exe during boot (after the kernel and smss.exe) |
| Service database | Registry key HKLM\SYSTEM\CurrentControlSet\Services, one key per service |
| Key values | ImagePath, Start, Type, ObjectName, DependOnService, FailureActions |
| SCM API | Functions to open, start, control, query and configure services |
| Your tools | services.msc, sc, PowerShell, Task Manager; all talk to the SCM |