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 in Visual Basic

Here is a summary description of the necessary tasks to create a Windows Service. These tasks are demonstrated later in a detailed example:

1. Create a new project of the type Windows Service. By default, the service will be in a module named Service1.vb, but it can be renamed, like any other .NET module. The class automatically placed in Service1.vb is named Service1 by default, and it inherits from the ServiceBase class.
2. Place any logic that needs to run when the service is started in the OnStart event of the service class. You can find the code listing for the Service1.vb file by double-clicking this file's design surface.
3. Add any additional logic that the service needs to carry out its operation. Logic can be placed in the class for the service, or in any other class module in the project. Such logic is typically called via some event that is generated by the operating system and passed to the service, such as a file changing in a directory, or a timer tick.
4. Add an installer to the project. This module provides the interface to the Windows operating system to install the module as a Windows Service. The installer is a class that inherits from System.Configuration.Install.Installer, and it contains instances of the ServiceProcessInstaller and ServiceInstaller classes.
5. Set the properties of the installer modules as necessary. The most common settings needed are the account under which the service will run and the name ...

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