Windows service

From Wikipedia, the free encyclopedia
(Redirected from Windows Service)
Jump to navigation Jump to search

In Windows NT operating systems, a Windows service is a computer program that operates in the background.[1] It is similar in concept to a Unix daemon.[1] 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.[2]

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

Administration

[edit | edit source]

Windows administrators can manage services via:

Services snap-in

[edit | edit source]

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

  • view a list of installed services along with service name, descriptions and configuration
  • start, stop, pause or restart services[5]
  • 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.[6]
    • 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

[edit | edit source]
sc
DevelopersMicrosoft, ReactOS Contributors
Repository
  • {{URL|example.com|optional display text}}Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).
Engine
    Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).
    Operating systemWindows, ReactOS
    TypeCommand
    LicenseWindows: Proprietary commercial software
    ReactOS: GNU General Public License
    Websitedocs.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.[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.[9]

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

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

    sc sub-commands
    Name Description Windows support 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

    [edit | edit source]

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

    C:\>sc query eventlog
    

    PowerShell

    [edit | edit source]

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

    Other management tools

    [edit | edit source]

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

    [edit | edit source]

    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

    [edit | edit source]

    Writing native services

    [edit | edit source]

    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

    [edit | edit source]

    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

    [edit | edit source]
    Windows services
    Concept

    References

    [edit | edit source]
    1. ^ a b c Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    2. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    3. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    4. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    5. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    6. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    7. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    8. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    9. ^ a b Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    10. ^ SC - Service Control - Windows CMD - SS64.com
    11. ^ reactos/sc.c at master · reactos/reactos · GitHub
    12. ^ a b MS-DOS and Windows command line sc command
    13. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    14. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    15. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    16. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    17. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    18. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    19. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    20. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    21. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    22. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    23. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    24. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    25. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).

    Further reading

    [edit | edit source]
    • Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    • David B. Probert, Windows Service Processes
    [edit | edit source]