Installing a Windows Service

Installing a Windows Service

Adding an Installer to the Project
Open the service1.vb design window, right click on it and select Add Installer option, which will add an installer project (called ProjectInstaller.vb) with two controls
— ServiceProcessInstaller1 and ServiceInstaller1 — to our existing project.
Select the ServiceInstaller1 control and open the property window. Change the ServiceName property and DisplayName property to MyService (this is the name you want to appear
in the list of services in the services window). Select the ServiceProcessInstaller1 control
and open the property window. Change the Account property to LocalSystem
(this needs to be specified as we need to run the service on our local machine).

Now it’s time for us to build the application and create an executable.
Select Build Solution from the Build menu to create an executable with
installation instructions for the service.

Installing the Service
To install our service we need to use the InstallUtil program, which is a .NET utility to install Windows services. You can find it in
C:\WINNT\Microsoft.NET\Framework\v1.0.3705
Note: This directory might be different on your computer, depending upon the
version of the .NET framework you are working with.
Alternatively, you could run a .NET Command Window by selecting

Start->Programs->Microsoft Visual Studio .NET->Visual Studio .NET Tool
->Visual Studio .NET Command Prompt

which sets all of the required paths for you.
Type the following command in the command window:

InstallUtil “d:\My documents\development\applications\
MyService\bin\Myservice.exe”

This is the path for the executable of the service we just created. Remember that VB.NET created the executable in the Bin folder under the project folder, so make sure you change this to your executable path.

Advertisements

%d bloggers like this: