Wednesday, October 30, 2013

Debugging a Windows Services

We cannot run Windows Services, directly like running a Windows or Web application; we need to install the Windows Service in the service console for it to operate. Hence we cannot debug windows services directly, use the following procedure to debug a windows service. 

Using ServiceController to Manage a Windows Service

We can use the ServiceController component to Start/Stop a service from an application without having to open the services panel. This can be used in Admin / Dashboard applications which needs to monitor and manage a set of services in a server.

The ServiceController is part of the “ System.ServiceProcess” assembly and has methods to start/stop or perform other operations on a Windows Service. In this post we shall see on how to use the ServiceController to manage the state of our Windows Service “NotificationServices”

Windows Services with custom User account

A Windows service runs under a specific account, the Account property needs to be set in the ServiceProcessInstaller. The property can take any of the below 4 values.


Creating a Deployment Project to Install a Windows Service

In the post Installing and Uninstalling a Windows Service, we have seen on how to Install and Un-Install a windows service using the InstallUtil tool, however when you want your service to be packaged for deployment into end user computer this approach might not work as the end user will not be aware of how to run the commands to install the service, in these cases we can create a deployment project which will automatically deploy the service to the computer.
In this post we shall see on how to create a Setup Project which will create a setup file to deploy the service. 

Installing and Uninstalling a Windows Service

Windows services can be installed and un-installed from the list of services, using the Utility installutil.exe, this utility comes with the framework and can be used to configure services. 
Follow the below instructions to use the installutil.exe utility to Install / UnInstall a windows service.