Saturday, February 25, 2012

How to create windows service & Setup file

Windows service is a service which enable us to create a long running executable application.Sometimes it is needed that one process will be executed in daily basis in that situation we can use windows service.To create a windows service we need to follow the following steps..
1>Create a windows service application by navigating ..
File->New->Project[See FIG-1]
FIG-1

2>Rename the service1 to appropiate service name.

3>Now open the service in design view.
4>Click on properties window.
5>Change the Name and service name property with the desired name.

6>Now open the service in design mode.
7>Right click on the design mode and click on Add Installer.

8>Two file[serviceProcessInstaller1,serviceInstaller] will be created.

9>Right click on serviceProcessInstaller and click on properties and change the account to LocalSysytem.

10>Now right click on serviceInstaller and change the SratType Property to Automatic and DisplayName to Service name

Now to create the setup file we need to follow the following steps..
1>Create a setup project in the same solution.

2>We can see Output file system structure by navigating the steps
Right CLick on Setup Project->View->File Sysytem

3>From the File system structure right click on the Application Folder->
Add->Project Output-Select Primary output->OK

4>Rightclick on set up project->View->Custom Action

5>In custom action interface Right click on Install->Add Custom Action
->Double click on application folder->Select The Primary output file

6>DO the step 5 for Uninstall
In custom action interface Right click on Uninstall->Add Custom Action
->Double click on application folder->Select The Primary output file
7>Open the ProjectInstaller.cs and add following line

8>Now build the project and build the set up project
Now Add code to test the service.
1>Open the service by right click on it and select view code.

2>Add the following code to test the service.
3>Right click on setup->Install->Specify Install Directory->Next->Service will be install into the windows service
4>To view the service RUN->Type->Services.msc
we can find our service

No comments: