http://www./KB/cs/MyWindowService.aspx
AbstractIn this article, I will describe how to implement, setup, install Windows Services with the help of snapshots. IntroductionA Windows Service is a program which runs continuously in the background of an Operating System. It was formerly known as NT services. Window service internally uses the Service Control Manager (SCM) of the operating system. A service must be installed in an SCM database before it can be launched. SCM controls the entire lifetime of each installed service. Implementing Windows services has become the choice of the current era of business as it requires minimum human intervention after deployment and gives long running functionality. We also say Window service application works as an Engine; once started it will keep running until the machine shuts down or gets some abnormal error. Building a Windows ServiceCreate a Windows Service project in Visual Studio 2005 as given below: File >> New >> Project It will open the New Project window. Choose the following settings:
Specify the location for the solution and let the solution name be Figure 1 – Creating new Windows service project using Visual Studio 2005 IDE
Click OK to create the solution and project. The IDE will automatically add a Service1.cs class file in the project Collapse
protected override void OnStart(string[] args)
Next, implement Collapse
public void EventAction(object sender)
Now we need to add installer components in the service project to set service setup properties. Installer components provided in Visual Studio automatically create Operating System environment objects like registry keys, Windows services control manager event handlers, executables for installation utilities when installing a service application, SCM initialization, etc. To Add Installer in the Windows ServiceOpen the MyService.cs file in design view. Right click on the form and choose Add Installer in the pop up menu: This will add a new file ProjectInstaller.cs with two controls, Now select the Build the Building a Setup for the Windows ServiceIn the solution " File >> Add >> New Project It will open the Add New Project window. Choose the following settings:
Right click on the project After clicking on "Add Custom Actions" a window will appear to select the item for the deployment. Double click on the "Application Folder." The "Add Output" button will be enabled now. Click on it to open the "Add Project Output Group" window. In this window, choose the "Primary Output" under Now Build the Installing Windows Service using IDEYou can use setup file MyServiceSetup.msi to install/uninstall the service To install It will open the window installer wizard. Click Next button and specify the installation folder location in the folder location text box. Click Next button. It will show you the confirmation window. Click Next to start the installation. It will show you the installing status and then completion message window. Now the service should be installed in the machine. Let us find and start the service as given in the next section. Starting the Installed Windows ServiceReach the installed Services following any of the methods given below. Open Service Control Manager: Control Panel >> Administrative Tools >> Services. OR Right click on My Computer, choose Manage. It will open the Computer Management window. In the tree view, open Services and Applications and click Services. OR In the Visual Studio 2005 IDE, open Server Explorer by pressing CTRL+ALT+S and choose node Services under the machine name of Servers tag. Find the Now the service |
|