Project requirements:
The database has a table that holds the address of the file to be downloaded, and the service requires the rotation to download the downloaded file.
The table structure is as follows:
Process:
- vs-- file -- New project -->windows-->windows service
- Add Setup Service1.cs Design Right-click Add Installer
- Select the ServiceInstaller1 Right-click service name to fill in the Custom service name
Fill in Magicfilemonitorservice here
- Select ServiceProcessInstaller1 Right-click account to select LocalSystem, This is the account used when the service is installed
- Create the install and uninstall files install.bat and uninstall.bat in the root directory, and right--- Properties -- Copy to output directory select Always copy
- Install.bat Writing
%systemroot%\microsoft.net\framework\v4.0.30319\installutil.exe C:\QMDownload\MongoDBFileDown\bin\Debug\ mongodbfiledown.exe--This is the exe file directory
Net Start magicfilemonitorservice--Open service
sc config magicfilemonitorservice start= auto--set the service to run automatically
pause--pausing to view the installation status in the CMD window
- Uninstall.bat Writing
%systemroot%\microsoft.net\framework\v4.0.30319\installutil.exe/u C:\QMDownload\MongoDBFileDown\bin\Debug\ mongodbfiledown.exe--This is the exe file directory
Pause
- Add a Timer control to the Servic1.cs.
9. Join the main program (not listed in detail)
10. Installation program
Bin found install.bat right -- Run as Administrator
Attention:
1.install.bat must right-click the administrator to run
2.timer1_elapsed add logic, must add OnStar content or not work
Annex (VS2013): 2016-07-06
CSharp the entire process of writing Windows services. rar
Maigcfilemonitor.rar
C # Writing Windows services