1. Create a Windows Service project named WindowsServiceTest;
2. Add a Windows Service item named TestService. cs;
3. Implement OnStart and OnEnd of the TestService class;
4. Right-click the design view of TestService, right-click the menu item Add Installer, and vs automatically creates a project Installer. cs class, ProjectInstaller. two serviceInstaller1 and serviceProcessInstaller1 members are automatically attached to cs. (In serviceInstaller1 and serviceProcessInstaller1, set the startup account and startup method according to the actual conditions)
5. After the Build is complete, create an install. bat batch file for installation as follows:
[Html]
C: \ Windows \ Microsoft. NET \ Framework \ v4.0.30319 \ installutil d: \ output \ WindowsServiceTest.exe
Pause
C: \ Windows \ Microsoft. NET \ Framework \ v4.0.30319 \ installutil d: \ output \ WindowsServiceTest.exe
Pause
For uninstallation:
[Html]
C: \ Windows \ Microsoft. NET \ Framework \ v4.0.30319 \ installutil d: \ output \ WindowsServiceTest.exe-u
Pause
C: \ Windows \ Microsoft. NET \ Framework \ v4.0.30319 \ installutil d: \ output \ WindowsServiceTest.exe-u
Pause