SimpleService.rar (26.75 kb)
In the first part we did the service skeleton so now we a custom installer for it...
Start by creating a separate class. I name my MyServiceInstaller.cs and add the following reference.
- using System;
- using System.ComponentModel;
- using System.Configuration.Install;
- using System.ServiceProcess;
We also need to add [RunInstaller(true)] that will enable the system to use InstallUtil.exe that is great tool that will install services to windows and inherit from the Installer class which we will use to make the installer.
In the constructor we need to add two objects for the system to install the service one is ServiceProcessInstaller that handles where the the process of the installation and the other one is ServiceInstaller that install the service.
Now we set the privileges in the process installer. We set to account Local System.
There a four settings that can be set with ServiceAccount
- LocalSystem : the service will have full priveleges, but most services do not require such.
- LocalService : acts like a non-priveleged user, as if anoymous
- NetworkService : provides extensive local priveleges , provide the credentials to remote servers
- User : any account choosen by the user.
Then we set some information regarding the service these can left out but I recommend that we set them.
- The display name is to set how it will shown up when you research
- And start type is to set the start up to automatic or manual or even disable.
Now we tell the installer what to install, by setting the exact of the service which is MySimpleService and finally add both installers to installers list which is in base class.