O'Reilly logo

Professional Visual Basic 2012 and .NET 4.5 Programming by Todd Herman, Gastón Hillar, David McCarter, Rob Windsor, Billy Hollis, Bill Sheldon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a Windows Service

Creating a Windows Service in .NET requires using several .NET classes, which provide the necessary interface to the operating system required by a Windows Service.

The .NET Framework Classes for Windows Services

Several base classes are needed to create a Windows Service:

  • System.ServiceProcess.ServiceBase—Provides the base class for the Windows Service. The class containing the logic that will run in the service inherits from ServiceBase. A single executable can contain more than one service, but each service in the executable is a separate class that inherits from ServiceBase.
  • System.Configuration.Install.Installer—This is a generic class that performs the installation chores for a variety of components. One class in a Windows Service process must inherit and extend Installer in order to provide the interface necessary to install the service under the various Windows operating systems.

Each class that inherits from Installer needs to contain an instance of each of the following classes:

  • System.ServiceProcess.ServiceProcessInstaller—This class contains the information needed to install a .NET executable that contains Windows Services (that is, an executable that contains classes that inherit from ServiceBase). The .NET installation utility for Windows Services (InstallUtil.exe, discussed later) calls this class to get the information it needs to perform the installation.
  • System.ServiceProcess.ServiceInstaller—This class also interacts with the InstallUtil.exe ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required