Windows service
{{short description|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.{{Cite web |url=http://msdn2.microsoft.com/en-us/library/ms685141.aspx |title=Services |work=Microsoft Developer Network |publisher=Microsoft |access-date=29 March 2013}}
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.{{cite web|title=New Elevation PowerToys for Windows Vista|url=https://technet.microsoft.com/en-us/magazine/2008.06.elevation.aspx|work=TechNet Magazine|publisher=Microsoft|access-date=21 June 2013|date=June 2008|quote=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.}}{{cite web|title=Services in Windows|url=http://msdn.microsoft.com/en-us/windows/hardware/gg463428.aspx|work=MSDN|publisher=Microsoft|access-date=21 June 2013|date=18 October 2010}}
Administration
Windows administrators can manage services via:
- The Services snap-in (found under Administrative Tools in Windows Control Panel)
- Sc.exe
- Windows PowerShell
=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:{{cite web|title=Services overview|url=https://technet.microsoft.com/en-us/library/cc783643%28v=ws.10%29.aspx|work=TechNet |publisher=Microsoft|access-date=29 March 2013}}
- view a list of installed services along with service name, descriptions and configuration
- start, stop, pause or restart services{{cite web|title=Start, stop, pause, resume, or restart a service|url=https://technet.microsoft.com/en-us/library/cc736564%28v=WS.10%29.aspx|work=TechNet|publisher=Microsoft|access-date=29 March 2013}}
- 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.{{cite web|title=ServiceInstaller.DelayedAutoStart Property (System.ServiceProcess)|url=http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceinstaller.delayedautostart.aspx|publisher=Microsoft|postscript=See Remarks section|access-date=28 November 2017}}
- 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=
{{Infobox software
| name = sc
| logo =
| screenshot =
| screenshot size =
| caption =
| developer = Microsoft, ReactOS Contributors
| released =
| latest release version =
| latest release date =
| operating system = Windows, ReactOS
| genre = Command
| license = Windows: Proprietary commercial software
ReactOS: GNU General Public License
| website = {{URL|https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/cc754599(v%3dws.11)}}
}}
The command-line tool to manage Windows services is sc.exe. It is available for all versions of Windows NT.
{{cite web|title=How to create a Windows service by using Sc.exe|url=http://support.microsoft.com/kb/251192 |work=Support |publisher=Microsoft |access-date=29 March 2013|date=11 September 2011}} This utility is included with Windows XP{{cite web|title=Command-line reference A-Z: SC|url=https://technet.microsoft.com/en-us/library/bb490995.aspx|work=TechNet|publisher=Microsoft|access-date=8 January 2014}} and later{{cite web|title=Command-Line Reference: Sc|url=https://technet.microsoft.com/en-us/library/cc754599.aspx|work=TechNet|publisher=Microsoft|access-date=8 January 2014|quote=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}} 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.[https://ss64.com/nt/sc.html SC - Service Control - Windows CMD - SS64.com]
The ReactOS version was developed by Ged Murphy and is licensed under the GPL.[https://github.com/reactos/reactos/blob/master/base/applications/sc/sc.c reactos/sc.c at master · reactos/reactos · GitHub]
class="wikitable sortable"
|+ sc sub-commands |
style="width:5em"| Name
!style="width:20em"| Description !style="width:20em"| Windows support !style="width:10em"| ReactOS support |
---|
query
| Show service status | {{Yes}} | {{Yes}} |
queryex
| Show extended service info (e.g. pid, flags) | {{Yes}} | {{Yes}} |
start
| Start a service | {{Yes}} | {{Yes}} |
pause
| Pause a service | {{Yes}} | {{Yes}} |
interrogate
| Send an INTERROGATE control request to a service | {{Yes}} | {{Yes}} |
continue
| Continue a service | {{Yes}} | {{Yes}} |
stop
| Stop a service | {{Yes}} | {{Yes}} |
config
| permanently change the service configuration | {{Yes}} | {{Yes}} |
description
| Change a service description | {{Yes}} | {{Yes}} |
failure
| Change the actions taken by a service upon failure | {{Yes}} | {{Yes}} |
failureflag
| | {{Yes}} | {{No}} |
sidtype
| | {{Yes}} | {{No}} |
privs
| | {{Yes}} | {{No}} |
managedaccount
| | {{Yes}} | {{No}} |
qc
| Show the service config (e.g. dependencies, full path etc.) | {{Yes}} | {{Yes}} |
qdescription
| Query a service description | {{Yes}} | {{Yes}} |
qfailure
| | {{Yes}} | {{No}} |
qfailureflag
| | {{Yes}} | {{No}} |
qsidtype
| | {{Yes}} | {{No}} |
qprivs
| | {{Yes}} | {{No}} |
qtriggerinfo
| | {{Yes}} | {{No}} |
qpreferrednode
| | {{Yes}} | {{No}} |
qmanagedaccount
| | {{Yes}} | {{No}} |
qprotection
| | {{Yes}} | {{No}} |
quserservice
| | {{Yes}} | {{No}} |
delete
| Delete a service | {{Yes}} | {{Yes}} |
create
| Create a service | {{Yes}} | {{Yes}} |
control
| Send a control to a service | {{Yes}} | {{Yes}} |
sdshow
| Display a service's security descriptor using SDDL | {{Yes}} | {{Yes}} |
sdset
| Sets a service's security descriptor using SDDL | {{Yes}} | {{Yes}} |
showsid
| | {{Yes}} | {{No}} |
triggerinfo
| | {{Yes}} | {{No}} |
preferrednode
| | {{Yes}} | {{No}} |
GetDisplayName
| Show the service DisplayName | {{Yes}} | {{Yes}} |
GetKeyName
| Show the service ServiceKeyName | {{Yes}} | {{Yes}} |
EnumDepend
| Show the service Dependencies | {{Yes}} | {{Yes}} |
boot
| | {{Yes}} | {{No}} |
Lock
| | {{Yes}} | {{No}} |
QueryLock
| | {{Yes}} | {{No}} |
==Examples==
The following example enumerates the status for active services & drivers.[https://www.computerhope.com/sc-command.htm MS-DOS and Windows command line sc command]
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:
- Get-Service{{cite web|title=Get-Service|url=https://technet.microsoft.com/library/hh849804.aspx|work=TechNet|publisher=Microsoft|access-date=29 March 2013}}
- New-Service{{cite web|title=New-Service|url=https://technet.microsoft.com/en-US/library/hh849830.aspx|work=TechNet|publisher=Microsoft|access-date=29 March 2013}}
- Restart-Service{{cite web|title=Restart-Service|url=https://technet.microsoft.com/en-US/library/hh849823.aspx|work=TechNet|publisher=Microsoft|access-date=29 March 2013}}
- Resume-Service{{cite web|title=Resume-Service|url=https://technet.microsoft.com/en-US/library/hh849811.aspx|work=TechNet|publisher=Microsoft|access-date=29 March 2013}}
- Set-Service{{cite web|title=Set-Service|url=https://technet.microsoft.com/en-US/library/hh849849.aspx|work=TechNet|publisher=Microsoft|access-date=29 March 2013}}
- Start-Service{{cite web|title=Start-Service|url=https://technet.microsoft.com/en-US/library/hh849825.aspx|work=TechNet|publisher=Microsoft|access-date=29 March 2013}}
- Stop-Service{{cite web|title=Stop-Service|url=https://technet.microsoft.com/en-US/library/hh849790.aspx|work=TechNet|publisher=Microsoft|access-date=29 March 2013}}
- Suspend-Service{{cite web|title=Suspend-Service|url=https://technet.microsoft.com/en-US/library/hh849791.aspx|work=TechNet|publisher=Microsoft|access-date=29 March 2013}}
=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.{{cite web|title=Start, stop, pause, resume, or restart a service|url=https://technet.microsoft.com/en-us/library/cc736564%28v=ws.10%29.aspx|work=TechNet|publisher=Microsoft|access-date=8 January 2014}} 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.{{cite web|title=INF AddService Directive|url=https://docs.microsoft.com/windows-hardware/drivers/install/inf-addservice-directive|publisher=Microsoft|access-date=10 July 2017}}{{cite web|title=SetupInstallServicesFromInfSection function|url=https://msdn.microsoft.com/library/aa377402.aspx|work=MSDN|publisher=Microsoft|access-date=10 July 2017}}{{cite web|title=SetupInstallServicesFromInfSectionEx function|url=https://msdn.microsoft.com/library/aa377403.aspx|work=MSDN|publisher=Microsoft|access-date=10 July 2017}}
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 [https://docs.microsoft.com/en-us/windows/win32/system-services 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.{{cite web|title=How To Create a User-Defined Service|url=http://support.microsoft.com/kb/137890|work=Support|publisher=Microsoft|access-date=29 March 2013}}
See also
; Windows services
- {{Section link|List of Microsoft Windows components|Services}}
- Windows Service Hardening
- svchost.exe
; Concept
References
{{reflist|30em}}
Further reading
- {{cite web |url=http://windowsitpro.com/windows/what-are-errorcontrol-start-and-type-values-under-services-subkeys |title=What are the ErrorControl, Start and Type values under the Services subkeys? |work=Windows IT Pro |publisher=Penton Media |date=5 March 1999 |access-date=29 March 2013 |first=John |last=Savill}}
- David B. Probert, [http://www.i.u-tokyo.ac.jp/edu/training/ss/lecture/new-documents/Lectures/11-WindowsServices/WindowsServices.ppt Windows Service Processes]
External links
{{Wikibooks|Guide to Windows Commands}}
- [https://technet.microsoft.com/en-us/sysinternals/bb963902.aspx Windows Sysinternals: Autoruns for Windows v13.4] – An extremely detailed query of services
- [https://www.poftut.com/service-management-windows-sc-command-line/ Service Management With Windows Sc From Command Line] – Windows Service Management Tutorial
- [https://github.com/patrikx3/service-manager-tray-for-windows/ Windows Service Manager Tray]
{{Microsoft Windows components}}
{{Windows commands}}