Let other users know how useful this tip is by rating it below. Got a tip or code of your own you'd like to share? Submit it here!
With .NET, developing a Windows Service is a piece of cake. VS.NET has a project template for creating Windows service. In this tip, I will walk you through the steps of creating a simple Windows service.
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
Step 1: Developing a service
From VS.NET File menu -> New -> Project, select the Windows Service project template.
The code for the WinService is pretty straight forward, there are events like:
And other events to get the most out of the Windows service.
Write the code in the respective event handlers, but remember a service will be running in the background. Don't write any kind of code which involves messages boxes, forms and other model UI elements.
Step 2: Building the service
From the design mode of the Windows service, right click, and from the menu select "AddInstaller," This will add two components on the designer, which will be used to install the service in the Service Control manager. Right click on the serviceprocessinstaller1 component and set the Account Property to "LocalSystem." And build the solution.
Step 3: Installing the service
After building the service, the next step is to install the service. This is done using the InstallUtil tool provided by Microsoft. Go to the bin folder of the WinService project in your HDD. You should find WindowsService1.exe. Use the installutil.exe tool as InstallUtil WindowsService1.exe. This will install the WindowsService1 as a service.
If you open the Service manager, you will be able to see Service1 in the list of services. You can manipulate the service as any other service by starting, stopping, setting the properties, etc.
That's it folks.