UGTS Document #29 - Last Modified: 8/29/2015 3:23 PM
A Service in Windows is any EXE or DLL which can be launched by the Service Control Manager (SCM) handled by services.exe, and meets the following requirements:
The SCM stores its configuration mostly under the registry key:
This key holds all the parameters needed for the SCM to start every service which has been installed on the machine, except for account passwords, which are stored in protected storage.
Security / Authorization
Because the SCM database is stored in the HKLM section of the registry, administrative privileges are required to install a service. Services can run under a built-in account, such as LocalSystem, Local Service, or Network Service, or they can run under a specified local or domain user account. If a service runs under a built-in account, no password needs to be stored to launch the service (because these built-in accounts do not have passwords). However, if the service is configured to run under a user account, then the password for the account (including the domain name) will be stored in the registry in the protected storage area. This password is saved using the API call LsaStorePrivateData, and the data is stored in the LSA secrets key:
Access to this key is restricted to only the LocalSystem account via ACLs, and the SCM calls LogonUserEx when launching the service, indirectly getting the password saved here by using the 'logon as a service' logon type. The service process (EXE or svchost.exe) then runs with the 'logon as a service' logon type under the given user account.
Service Installation (.NET)
In .NET, a Windows service can be installed in a number of ways. Here are two of the ways:
If you use either of the above two methods, you'll need to create a class with the RunInstaller(True) attribute. It can be a little hard to understand what this class is supposed to do - because it is not really supposed to do anything except to add Installer objects in the constructor to the Installers collection, each with the appropriate parameters to install whatever object should be installed. The constructor will be invoked whether you are installing or uninstalling, so you should not use the constructor to prompt for user input. You can, but the prompt will also come up at the uninstall, which will be confusing.
Another point to remember is that this RunInstaller class must be defined in the
entry assembly for the service, and not in a different DLL. This is
because you must pass the path to the specific EXE / DLL which contains your
class to the InstallHelper function, and this function will assume that this EXE
/ DLL is to be your entry point (this cannot be changed in the