1. New Project Select Windows Service
2. Add installation program
3. Modify the Installation code
ServiceProcessInstaller Processinstall; ServiceInstaller ServiceInstall; Public ProjectInstaller () { This.processinstall = new ServiceProcessInstaller (); This.serviceinstall = new ServiceInstaller (); Processinstall.account = Serviceaccount.localsystem; This.serviceInstall.ServiceName = "Abc_taskservice"; This.serviceInstall.Description = "Abc_description"; This. Installers.add (This.serviceinstall); This. Installers.add (This.processinstall); }
4. Rebuild the project
5. New BAT file (install service. bat)
@ECHO Offrem The following directory is for. Net1.1set Dotnetfx=%systemroot%\microsoft.net\framework\v4.0.30319set path=%path%;%d OTNETFX%CDcd "G:\WindowsServiceTest\WindowsServiceTest\bin\Debug"Echo is installing the test service echo--------------------- ------------------------------installutil/i WindowsServiceTest.exesc config "Abc_taskservice" start= AutoNet Start "Abc_taskservice"echo---------------------------------------------------Pause
Attention:
1. The CD "G:\WindowsServiceTest\WindowsServiceTest\bin\Debug" path is the path of the project
2. installutil/i WindowsServiceTest.exe where windowsservicetest the name of the file that was rebuilt for the project
3. sc config "abc_taskservice" start= Auto where Abc_taskservice is the name of the service from the third step
4, the bat file must be executed at the Administrator: command prompt operation otherwise will be wrong (unable to open the Count machine.) on the Service Control manager, Access denied, etc.
6. New BAT file (uninstall service. bat)
@ECHO Offrem The following directory is for. Net1.1set Dotnetfx=%systemroot%\microsoft.net\framework\v4.0.30319set path=%path%;%d OTNETFX%CDCD "G:\WindowsServiceTest\WindowsServiceTest\bin\Debug" Echo is uninstalling the test service echo------------------------------ ---------------------installutil/u Windowsservicetest.exeecho-------------------------------------------------- -pause
Installation Services. Bat Download
Uninstall the service. Bat download
Windows Services installation, uninstallation