Demo and windowsservicedemo are attached to the development steps of Windows service.
1. Open VS, create a project, select Windows Services, set the Directory and project name, and click OK.
2. Expand the Service1 service file and write the service1.cs file, instead of Service1 [design]. Then modify the OnStart and OnStop methods.
3. Compile the service code. Here we will not mention the simple log writing function... Check the Code. If you do not understand it, check the Demo.
4. Configure the WindowsService installer. Switch to the design view, right-click, and choose add installer from the shortcut menu.
5. On the installer interface, select ** ProcessInstaller1, then F4 to view the attributes, and change the Account to LocalService. Select ** Installer1, F4 to view attributes, Description service Description, DisplayName service friendly display name, and service Identification name in ServiceName system. do not duplicate the name with the system service and ensure it is unique, startType, select AutoMatic ).
6. Generate a solution. Then we start to install the service to the system. If F5 is generated directly, an error will be reported. This will not be demonstrated here. Open the CMD Command Prompt window.
We use the. Net Framework automatic tool InstallUtil.exe for installation. First, find the directory where it is located. My local directory is: C: \ Windows \ Microsoft. NET \ Framework \ v4.0.30319.
Depending on your PC and the. net Framework Version, switch to the corresponding directory and run cd in the CMD window.
Then execute the installation service command: InstallUtil.exe path where your Windows service is generated. For example, the path of my service is F: \ Work \ WindowsService \ bin \ Debug \ WindowsService.exe.
Command: InstallUtil.exe F: \ Work \ WindowsService \ bin \ Debug \ WindowsService.exe
This indicates that the service has been installed successfully. Now let's go to the computer service to view the services we wrote. Right-click a computer and choose computer management from the shortcut menu on the left.
Find the service item of DisplayName (Windows Service Demo ).
Right-click to start... Open the log file to check whether the service is running properly ., The service is running normally.
7. Run the following command to uninstall the service: InstallUtil.exe/u.
By now, Windows Service Development is complete.
8, Demo: http://files.cnblogs.com/moretry/WindowsServiceDemo.zip
If you have any questions, please kindly advise. Please indicate the source for reprinting. Thank you.