Windows service installation

To install a windows service you just built, here is some extra work you need to do. First have these two classes in your windows service project to configure the installation.

    [RunInstaller(true)]
    public class Installer : ServiceInstaller
    {
        public Installer()
        {
            DisplayName = "My Windows Service";
            Description = "Does cool things";
            ServiceName = "MyWindowsService";
        }
    }

    [RunInstaller(true)]
    public class ProcessInstaller : ServiceProcessInstaller
    {
        public ProcessInstaller()
        {
            Account = ServiceAccount.LocalService;
        }
    }

Next part is easy… Start the Visual Studio Commmand Prompt and go to the folder where this service is built. Run this to install the service:

installutil MyWindowsService.exe

Then go to Services in your in Computer Management to start the service. To uninstall the service; stop the service and then run:

installutil /u MyWindowsService.exe

That’s all…