1. Create a Windows Service Project myservice.
2. Complete the onstart and onstop methods in the myservice class to start and stop the service.
Note: We recommend that you place the processing content in a separate project. When debugging Windows Services, you can directly allow the independent project instead of using the Windows service.
For example, the independent object uses: public static readonly serviceprocesser processerinstance = newservcieprocesser. serviceprocesser (); the call uses: servcieprocesser. serviceprocesser. processerinstance. onstart ();
3. Add and installProgramClass, right-click the project and choose "add"> "new item"> "template" and select "Installer class": myserviceinstaller.
4. Add the following content to the constructor:
// create the serviceprocessinstaller object and serviceinstaller object
system. serviceprocess. serviceprocessinstaller spinstaller =
new system. serviceprocess. serviceprocessinstaller ();
system. serviceprocess. serviceinstaller sinstaller =
new system. serviceprocess. serviceinstaller ();
// Set the account, user name, and password of the serviceprocessinstaller object
Spinstaller. Account = system. serviceprocess. serviceaccount. LocalSystem;
// This. spinstaller. Username = NULL;
// This. spinstaller. Password = NULL;
// Set the service name
Sinstaller. servicename = "myservice ";
Sinstaller. Description = "*** service name ";
// Set the Service Startup Mode
Sinstaller. starttype = system. serviceprocess. servicestartmode. Automatic;
Installers. addrange (
New system. configuration. Install. installer [] {spinstaller, sinstaller });
5. Generate a project and complete the service project.
6. Install through batch processing: Write the following content in the BAT file.
Installutil faisetuservice.exe
Unmount through batch processing: in the BAT file:
Installutil/u faisetuservice.exe
[Note]: installutil.exe, installutillib. dll