Windows service
In Windows NT operating systems, a Windows service is a computer program that operates in the background. It is similar in concept to a Unix daemon. A Windows service must conform to the interface rules and protocols of the Service Control Manager, the component responsible for managing Windows services. It is the Services and Controller app, services.exe, that launches all the services and manages their actions, such as start, end, etc.
Windows services can be configured to start when the operating system is started and run in the background as long as Windows is running. Alternatively, they can be started manually or by an event. Windows NT operating systems include numerous services which run in context of three user accounts: System, Network Service and Local Service. These Windows components are often associated with Host Process for Windows Services. Because Windows services operate in the context of their own dedicated user accounts, they can operate when a user is not logged on.
Prior to Windows Vista, services installed as an "interactive service" could interact with Windows desktop and show a graphical user interface. In Windows Vista, however, interactive services are deprecated and may not operate properly, as a result of Windows Service hardening.
Administration
Windows administrators can manage services via:- The Services snap-in
- Sc.exe
- Windows PowerShell
Services snap-in
- view a list of installed services along with service name, descriptions and configuration
- start, stop, pause or restart services
- specify service parameters when applicable
- change the startup type. Acceptable startup types include:
- *Automatic: The service starts at system startup.
- *Automatic : The service starts a short while after the system has finished starting up. This option was introduced in Windows Vista in an attempt to reduce the boot-to-desktop time. However, not all services support delayed start.
- *Manual: The service starts only when explicitly summoned.
- *Disabled: The service is disabled. It will not run.
- change the user account context in which the service operates
- configure recovery actions that should be taken if a service fails
- inspect service dependencies, discovering which services or device drivers depend on a given service or upon which services or device drivers a given service depends
- export the list of services as a text file or as a CSV file
Command line
The
sc command's scope of management is restricted to the local computer. However, starting with Windows Server 2003, not only can sc do all that the Services snap-in does, but it can also install and uninstall services.The
sc command duplicates some features of the net command.The ReactOS version was developed by Ged Murphy and is licensed under the GPL.
| Name | Description | Windows support | ReactOS support |
| query | Show service status | ||
| queryex | Show extended service info | ||
| start | Start a service | ||
| pause | Pause a service | ||
| interrogate | Send an INTERROGATE control request to a service | ||
| continue | Continue a service | ||
| stop | Stop a service | ||
| config | permanently change the service configuration | ||
| description | Change a service description | ||
| failure | Change the actions taken by a service upon failure | ||
| failureflag | |||
| sidtype | |||
| privs | |||
| managedaccount | |||
| qc | Show the service config | ||
| qdescription | Query a service description | ||
| qfailure | |||
| qfailureflag | |||
| qsidtype | |||
| qprivs | |||
| qtriggerinfo | |||
| qpreferrednode | |||
| qmanagedaccount | |||
| qprotection | |||
| quserservice | |||
| delete | Delete a service | ||
| create | Create a service | ||
| control | Send a control to a service | ||
| sdshow | Display a service's security descriptor using SDDL | ||
| sdset | Sets a service's security descriptor using SDDL | ||
| showsid | |||
| triggerinfo | |||
| preferrednode | |||
| GetDisplayName | Show the service DisplayName | ||
| GetKeyName | Show the service ServiceKeyName | ||
| EnumDepend | Show the service Dependencies | ||
| boot | |||
| Lock | |||
| QueryLock |
Examples
The following example enumerates the status for active services & drivers.C:\>sc query
The following example displays the status for the Windows Event log service.
C:\>sc query eventlog
PowerShell
The Microsoft.PowerShell.Management PowerShell module has several cmdlets which can be used to manage Windows services:- Get-Service
- New-Service
- Restart-Service
- Resume-Service
- Set-Service
- Start-Service
- Stop-Service
- Suspend-Service
Other management tools
net command can start, stop, pause or resume a Windows service. In Windows Vista and later, Windows Task Manager can show a list of installed services and start or stop them. MSConfig can enable or disable Windows services.Installation
Windows services are installed and removed via *.INF setup scripts by SetupAPI; an installed service can be started immediately following its installation, and a running service can be stopped before its deinstallation.Development
Writing native services
For a program to run as a Windows service, the program needs to be written to handle service start, stop, and pause messages from the Service Control Manager through the . SCM is the Windows component responsible for managing service processes.Wrapping applications as a service
The Windows Resource Kit for Windows NT 3.51, Windows NT 4.0 and Windows 2000 provides tools to control the use and registration of services:SrvAny.exe acts as a service wrapper to handle the interface expected of a service and allow any executable or script to be configured as a service. Sc.exe allows new services to be installed, started, stopped and uninstalled.