1)How to Create windows service
2)How to create Windows Service installation using Msi
How to Create windows service
-----------------------------
Step 1:(Create Windows Service Project Using Visual Studio)
File-->New-->Project-->Visual C#(Visual basic)-->Windows-->Windows Service-->Ok
step 2: select service1.cs and View Code
protected override void OnStart(string[] args)
{
//Here we can Write code what we need to on while service Started.
EventLog.WriteEntry("service created");
}
protected override void OnStop()
{
//Here we can Write code what we need to on while service stopping.
EventLog.WriteEntry("service created");
}
step 3: (need to add service installer)
Select the service1.cs design view and right click the designer view
then select add installer.
Project installer file will create automatically
sample screen:
step 4 : Project installer --->select service installer1 tool--->properties-->
update following fields
1) starttype == Automatic
2)description , display Name ect... for service related information
fields you can add
step 5 : Project installer --->select serviceprocessinstaller1-->properties
Account-->Local system(it won't ask user name password,if you select user then we need to pass user name like domainname\username, password)
step 6:select project -->properties -->application-->startup object-->select your project program file
step 7:build and release the file
using installutil.exe we can test windows service,it will be located dot net framework 2.0 folder.
using command prompt installing windows service
installutil C:\servicetest.exe
using command prompt Uninstalling windows service
installutil /u C:\servicetest.exe
Your service Created,now how we can create setup and deployment file
step 1:
create new setup and deployment project
select setup and deployment project-->right click-->add-->project output-->primary output--Ok
step 2:
select project-->right click-->view-->Custom actions-->
select custom actions-->right click-->Application folder-->
primary output from servicename(Active)-->ok
step 3:
Build and test setup file.
happy coding...