Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
From the author of


Even before a service can run, it needs to be registered with the Service Control Manager (SCM). In order to do this, the .NET Framework includes the concept of installers. Simply put, if an assembly contains a class derived from System.Configuration.Install.Installer (an "installer class") that is decorated with the RunInstaller attribute, the installUtil.exe command-line utility can be used to activate the installer and install whatever components it specifies. In other words, before a Windows service can run, it must be installed at the command prompt using installUtil.exe.

Although having an installer class is necessary, it is not sufficient. In order to actually install the service, you'll need to add instances of the ServiceInstaller and ServiceProcessInstaller classes found in the System.ServiceProcess namespace to the Installers collection of the installer class. Of course, you'll also need to do some minimal configuration of these objects to identify the service name, the account under which it should run, and its start mode.

In addition to actually performing the registration with the SCM, the installer class provides an opportunity to make any changes to the machine on which the service is going to run. Because the service will be installed by an Administrator, for example, you can override the Install method of the installer class and add code to create any registry settings that the service requires.

  • + Share This
  • 🔖 Save To Your Account