1. Create a new project, or select the current solution - right click - add - new project
2. Select (Project Type) Visual C # project, (Template) Windows Service, fill in the service name to be created, and then press the OK button.
3. A WindowsService1 project is created by default in the resource manager, and a Service.cs file is included under the project
4. Switch from code view to design view, right-click and select " Add Installer "
5. Then, in the current project explorer, you will find an additional ProjectInstaller.cs file. Click the file to open the ProjectInstaller.cs [ design ] form. You will find that there are two components "servi ceProcessInstaller1" and "serviceInstaller1" automatically .
6. Set the attributes of the serviceInstaller1 component : ServiceName = MyService (the name is arbitrary ) and StartType = Automation (automatically starts at boot)
7. Set the attribute of the serviceProcessInstaller1 component: Accout = LocalSystem
8, select the current solution, right - regenerate. There will be one more exe file under the debug file
9. Windows server registration Open the command-line tool that comes with Visual Studio , right-click and select Run as administrator, then enter the following command:
InstallUtil D: /service.exe ( service.exe is the exe file generated by the project just now )
Uninstall service
InstallUtil / u D: /service.exe
After this, you can see the service just installed in the service management interface.