Menu
Home Explore People Places Arts History Plants & Animals Science Life & Culture Technology
On this page
Windows service
Component of the Microsoft Windows operating system

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.

We don't have any images related to Windows service yet.
We don't have any YouTube videos related to Windows service yet.
We don't have any PDF documents related to Windows service yet.
We don't have any Books related to Windows service yet.
We don't have any archived web articles related to Windows service yet.

Administration

Windows administrators can manage services via:

Services snap-in

The Services snap-in, built upon Microsoft Management Console, can connect to the local computer or a remote computer on the network, enabling users to:6

  • view a list of installed services along with service name, descriptions and configuration
  • start, stop, pause or restart services7
  • specify service parameters when applicable
  • change the startup type. Acceptable startup types include:
    • Automatic: The service starts at system startup.
    • Automatic (Delayed): 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.8
    • 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 command-line tool to manage Windows services is sc.exe. It is available for all versions of Windows NT.9 This utility is included with Windows XP10 and later11 and also in ReactOS.

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.12

The sc command duplicates some features of the net command.13

The ReactOS version was developed by Ged Murphy and is licensed under the GPL.14

sc sub-commands
NameDescriptionWindows supportReactOS support
queryShow service statusYesYes
queryexShow extended service info (e.g. pid, flags)YesYes
startStart a serviceYesYes
pausePause a serviceYesYes
interrogateSend an INTERROGATE control request to a serviceYesYes
continueContinue a serviceYesYes
stopStop a serviceYesYes
configpermanently change the service configurationYesYes
descriptionChange a service descriptionYesYes
failureChange the actions taken by a service upon failureYesYes
failureflagYesNo
sidtypeYesNo
privsYesNo
managedaccountYesNo
qcShow the service config (e.g. dependencies, full path etc.)YesYes
qdescriptionQuery a service descriptionYesYes
qfailureYesNo
qfailureflagYesNo
qsidtypeYesNo
qprivsYesNo
qtriggerinfoYesNo
qpreferrednodeYesNo
qmanagedaccountYesNo
qprotectionYesNo
quserserviceYesNo
deleteDelete a serviceYesYes
createCreate a serviceYesYes
controlSend a control to a serviceYesYes
sdshowDisplay a service's security descriptor using SDDLYesYes
sdsetSets a service's security descriptor using SDDLYesYes
showsidYesNo
triggerinfoYesNo
preferrednodeYesNo
GetDisplayNameShow the service DisplayNameYesYes
GetKeyNameShow the service ServiceKeyNameYesYes
EnumDependShow the service DependenciesYesYes
bootYesNo
LockYesNo
QueryLockYesNo

Examples

The following example enumerates the status for active services & drivers.15

C:\>sc query

The following example displays the status for the Windows Event log service.16

C:\>sc query eventlog

PowerShell

The Microsoft.PowerShell.Management PowerShell module (included with Windows) has several cmdlets which can be used to manage Windows services:

  • Get-Service17
  • New-Service18
  • Restart-Service19
  • Resume-Service20
  • Set-Service21
  • Start-Service22
  • Stop-Service23
  • Suspend-Service24

Other management tools

Windows also includes components that can do a subset of what the snap-in, Sc.exe and PowerShell do. The net command can start, stop, pause or resume a Windows service.25 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 (see startup type description above) 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.262728

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 (SCM) through the System Services API. 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 (e.g. handle service_start and respond sometime later with service_started or service_failed) and allow any executable or script to be configured as a service. Sc.exe allows new services to be installed, started, stopped and uninstalled.29

See also

Windows services Concept

Further reading

Wikibooks has a book on the topic of: Guide to Windows Commands

References

  1. "Services overview". TechNet. Microsoft. Retrieved 29 March 2013. https://technet.microsoft.com/en-us/library/cc783643%28v=ws.10%29.aspx

  2. "Services overview". TechNet. Microsoft. Retrieved 29 March 2013. https://technet.microsoft.com/en-us/library/cc783643%28v=ws.10%29.aspx

  3. "Services". Microsoft Developer Network. Microsoft. Retrieved 29 March 2013. http://msdn2.microsoft.com/en-us/library/ms685141.aspx

  4. "New Elevation PowerToys for Windows Vista". TechNet Magazine. Microsoft. June 2008. Retrieved 21 June 2013. The service CmdAsSystem is configured as interactive whose support is being deprecated. The service may not function properly. The problem is that this script tries to create and start an interactive service. Interactive services will not function correctly due to Session 0 Isolation in Windows Vista. https://technet.microsoft.com/en-us/magazine/2008.06.elevation.aspx

  5. "Services in Windows". MSDN. Microsoft. 18 October 2010. Retrieved 21 June 2013. http://msdn.microsoft.com/en-us/windows/hardware/gg463428.aspx

  6. "Services overview". TechNet. Microsoft. Retrieved 29 March 2013. https://technet.microsoft.com/en-us/library/cc783643%28v=ws.10%29.aspx

  7. "Start, stop, pause, resume, or restart a service". TechNet. Microsoft. Retrieved 29 March 2013. https://technet.microsoft.com/en-us/library/cc736564%28v=WS.10%29.aspx

  8. "ServiceInstaller.DelayedAutoStart Property (System.ServiceProcess)". Microsoft. Retrieved 28 November 2017See Remarks section{{cite web}}: CS1 maint: postscript (link) http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceinstaller.delayedautostart.aspx

  9. "How to create a Windows service by using Sc.exe". Support. Microsoft. 11 September 2011. Retrieved 29 March 2013. http://support.microsoft.com/kb/251192

  10. "Command-line reference A-Z: SC". TechNet. Microsoft. Retrieved 8 January 2014. https://technet.microsoft.com/en-us/library/bb490995.aspx

  11. "Command-Line Reference: Sc". TechNet. Microsoft. Retrieved 8 January 2014. Windows 7, Windows 8, Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1, Windows Server 2003 with SP2, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Vista https://technet.microsoft.com/en-us/library/cc754599.aspx

  12. "Command-Line Reference: Sc". TechNet. Microsoft. Retrieved 8 January 2014. Windows 7, Windows 8, Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1, Windows Server 2003 with SP2, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Vista https://technet.microsoft.com/en-us/library/cc754599.aspx

  13. SC - Service Control - Windows CMD - SS64.com https://ss64.com/nt/sc.html

  14. reactos/sc.c at master · reactos/reactos · GitHub https://github.com/reactos/reactos/blob/master/base/applications/sc/sc.c

  15. MS-DOS and Windows command line sc command https://www.computerhope.com/sc-command.htm

  16. MS-DOS and Windows command line sc command https://www.computerhope.com/sc-command.htm

  17. "Get-Service". TechNet. Microsoft. Retrieved 29 March 2013. https://technet.microsoft.com/library/hh849804.aspx

  18. "New-Service". TechNet. Microsoft. Retrieved 29 March 2013. https://technet.microsoft.com/en-US/library/hh849830.aspx

  19. "Restart-Service". TechNet. Microsoft. Retrieved 29 March 2013. https://technet.microsoft.com/en-US/library/hh849823.aspx

  20. "Resume-Service". TechNet. Microsoft. Retrieved 29 March 2013. https://technet.microsoft.com/en-US/library/hh849811.aspx

  21. "Set-Service". TechNet. Microsoft. Retrieved 29 March 2013. https://technet.microsoft.com/en-US/library/hh849849.aspx

  22. "Start-Service". TechNet. Microsoft. Retrieved 29 March 2013. https://technet.microsoft.com/en-US/library/hh849825.aspx

  23. "Stop-Service". TechNet. Microsoft. Retrieved 29 March 2013. https://technet.microsoft.com/en-US/library/hh849790.aspx

  24. "Suspend-Service". TechNet. Microsoft. Retrieved 29 March 2013. https://technet.microsoft.com/en-US/library/hh849791.aspx

  25. "Start, stop, pause, resume, or restart a service". TechNet. Microsoft. Retrieved 8 January 2014. https://technet.microsoft.com/en-us/library/cc736564%28v=ws.10%29.aspx

  26. "INF AddService Directive". Microsoft. Retrieved 10 July 2017. https://docs.microsoft.com/windows-hardware/drivers/install/inf-addservice-directive

  27. "SetupInstallServicesFromInfSection function". MSDN. Microsoft. Retrieved 10 July 2017. https://msdn.microsoft.com/library/aa377402.aspx

  28. "SetupInstallServicesFromInfSectionEx function". MSDN. Microsoft. Retrieved 10 July 2017. https://msdn.microsoft.com/library/aa377403.aspx

  29. "How To Create a User-Defined Service". Support. Microsoft. Retrieved 29 March 2013. http://support.microsoft.com/kb/137890