What is the difference between a windows service and a regular application?

17,661

Solution 1

There are a couple of things that jump out to me immediately.

  • They run in an entirely different console starting with Vista
  • As a result of running in a different console, services cannot interact with the desktop. So essentially there is no direct UI support. You typically have to code a sibling UI application that does run as a normal program and uses some mechanism (named pipes for example) to communicate with the service.
  • Typically only one instance of your service can be running at any given time.
  • Processes are per user, services are per work station and hence often provide services for multiple users.

Solution 2

This MSDN page leads to more documentation on creating them than you could shake a stick at. This page is perhaps a better introduction to them in general.

The key difference between a process running as an app versus as a service is that the service can operate entirely outside the normal association with a user and session. Thus services can run such that they start before any user logs in and can continue running after users log off. Services are thus used to implement a great deal of the actual functionality of the operating system.

Services are also not tied to running as a 1:1 mapping with a process. Many services can exist within one process, normally through the use of svchost (take a look at these with process explorer for an indication of how this often works). This reduces the effort at startup as multiple processes are not required for relatively lightweight services.

Implementing a service in c# is pretty simple, this page indicates how in very easy to follow terms.

Note that in reality a service in windows is little more that the scaffolding in the registry under HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services which defines those 'image paths' (in most cases simply executables and the parameters to use) which are considered services along with which user then run as, which other services they depend on and whether they start at start up/post start up or as required.

Solution 3

If you're familiar with Unix, a Windows service is like a Unix daemon. It isn't associated with any particular user, and is always running in the background.

Share:
17,661
Lemon
Author by

Lemon

Software Developer, Geek, HSP, SDA, ..., open, honest, careful, perfectionist, ... Currently into indoor rowing and rock climbing, just to mention something non-computer-related... Not the best at bragging about myself... so... not sure what more to write... 🤔

Updated on June 04, 2022

Comments

  • Lemon
    Lemon almost 2 years

    I have only created regular windows applications (C# mostly). What differentiates a windows service from a regular windows application? What makes them different? What can a service do that an application can't? What are the differences seen from a developers point of view? How do you create one? Is it just to create a regular application (Console application maybe, since there are no gui?) and run or install it in a special way, or is it more that has to be done?

  • Rich
    Rich over 14 years
    I'd rather say that you can have services running without any interactive sessions on the machine. You can start lots or programs when the user logs on in various ways. Using a service isn't really a benefit there.