Summery
A Windows Service is a long-running background executable or application managed by the Service Control Manager and is similar to the concept of daemons on Unix systems.
They can be controlled using:
- Services app (GUI)
- PowerShell
- sc.exe (CLI)
Each service runs as a user account that determines its permissions:
- LocalSystem - Very powerful, almost full system access
- Network Service - Limited account, can access network resources
- Local Service - Very limited local permissions
- Custom user - A specific local/domain account chosen by the creator
The account decides what the service is allowed to do.
Commands
For Windows services, these are the main commands worth remembering:
| Action | PowerShell | CMD |
|---|---|---|
| List services | Get-Service | sc.exe query |
| All services | Get-CimInstance Win32_Service | sc.exe query type= service state= all |
| Running only | Get-Service | ? Status -eq Running | sc.exe query state= active |
| Status | (Get-Service mysql).Status | sc.exe query mysql |
| Start | Start-Service mysql | sc.exe start mysql |
| Stop | Stop-Service mysql | sc.exe stop mysql |
| Restart | Restart-Service mysql | sc.exe stop mysql + sc.exe start mysql |
| Disable | Set-Service mysql -StartupType Disabled | sc.exe config mysql start= disabled |
| Enable | Set-Service mysql -StartupType Automatic | sc.exe config mysql start= auto |
| Service details | Get-Service mysql | Format-List * | sc.exe qc mysql |
| Startup type | (Get-Service mysql).StartType | sc.exe qc mysql |
| Dependencies | (Get-Service mysql).ServicesDependedOn | sc.exe qc mysql |
| Dependents | (Get-Service mysql).DependentServices | sc.exe qc mysql |
| Service executable | Get-CimInstance Win32_Service -Filter "Name='mysql'" | select PathName | sc.exe qc mysql |
| Note: | ||
sc.exe is the naming used in PowerShell to run that CMD command. Inside CMD, you can refer to it as sc. This issue exists, because in PowerShell sc means Set-Content. |
Resources
Some well-known attack paths conneced to services are: