Windows service explained

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.[1]

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.[2] [3]

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:[4]

Command line

sc
Developer:Microsoft, ReactOS Contributors
Operating System:Windows, ReactOS
Genre:Command
License:Windows: Proprietary commercial software
ReactOS: GNU General Public License

The command-line tool to manage Windows services is sc.exe. It is available for all versions of Windows NT.[7] This utility is included with Windows XP[8] and later[9] 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.

The sc command duplicates some features of the [[net (command)|net]] command.[10]

The ReactOS version was developed by Ged Murphy and is licensed under the GPL.[11]

sc sub-commands
NameDescriptionWindows supportReactOS support
queryShow service status
queryexShow extended service info (e.g. pid, flags)
startStart a service
pausePause a service
interrogateSend an INTERROGATE control request to a service
continueContinue a service
stopStop a service
configpermanently change the service configuration
descriptionChange a service description
failureChange the actions taken by a service upon failure
failureflag
sidtype
privs
managedaccount
qcShow the service config (e.g. dependencies, full path etc.)
qdescriptionQuery a service description
qfailure
qfailureflag
qsidtype
qprivs
qtriggerinfo
qpreferrednode
qmanagedaccount
qprotection
quserservice
deleteDelete a service
createCreate a service
controlSend a control to a service
sdshowDisplay a service's security descriptor using SDDL
sdsetSets a service's security descriptor using SDDL
showsid
triggerinfo
preferrednode
GetDisplayNameShow the service DisplayName
GetKeyNameShow the service ServiceKeyName
EnumDependShow the service Dependencies
boot
Lock
QueryLock

Examples

The following example enumerates the status for active services & drivers.[12] 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 (included with Windows) has several cmdlets which can be used to manage Windows services:

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)|net]] command can start, stop, pause or resume a Windows service.[21] 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.[22] [23] [24]

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.[25]

See also

Windows services
Concept

Further reading

External links

Notes and References

  1. Web site: Services . . Microsoft . 29 March 2013.
  2. Web site: New Elevation PowerToys for Windows Vista. TechNet Magazine. Microsoft. 21 June 2013. June 2008. 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..
  3. Web site: Services in Windows. MSDN. Microsoft. 21 June 2013. 18 October 2010.
  4. Web site: Services overview. . Microsoft. 29 March 2013.
  5. Web site: Start, stop, pause, resume, or restart a service. TechNet. Microsoft. 29 March 2013.
  6. Web site: ServiceInstaller.DelayedAutoStart Property (System.ServiceProcess). Microsoft. See Remarks section. 28 November 2017.
  7. Web site: How to create a Windows service by using Sc.exe. Support . Microsoft . 29 March 2013. 11 September 2011.
  8. Web site: Command-line reference A-Z: SC. TechNet. Microsoft. 8 January 2014.
  9. Web site: Command-Line Reference: Sc. TechNet. Microsoft. 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.
  10. https://ss64.com/nt/sc.html SC - Service Control - Windows CMD - SS64.com
  11. https://github.com/reactos/reactos/blob/master/base/applications/sc/sc.c reactos/sc.c at master · reactos/reactos · GitHub
  12. https://www.computerhope.com/sc-command.htm MS-DOS and Windows command line sc command
  13. Web site: Get-Service. TechNet. Microsoft. 29 March 2013.
  14. Web site: New-Service. TechNet. Microsoft. 29 March 2013.
  15. Web site: Restart-Service. TechNet. Microsoft. 29 March 2013.
  16. Web site: Resume-Service. TechNet. Microsoft. 29 March 2013.
  17. Web site: Set-Service. TechNet. Microsoft. 29 March 2013.
  18. Web site: Start-Service. TechNet. Microsoft. 29 March 2013.
  19. Web site: Stop-Service. TechNet. Microsoft. 29 March 2013.
  20. Web site: Suspend-Service. TechNet. Microsoft. 29 March 2013.
  21. Web site: Start, stop, pause, resume, or restart a service. TechNet. Microsoft. 8 January 2014.
  22. Web site: INF AddService Directive. Microsoft. 10 July 2017.
  23. Web site: SetupInstallServicesFromInfSection function. MSDN. Microsoft. 10 July 2017.
  24. Web site: SetupInstallServicesFromInfSectionEx function. MSDN. Microsoft. 10 July 2017.
  25. Web site: How To Create a User-Defined Service. Support. Microsoft. 29 March 2013.