使用C#.NET开发Windows服务并安装部署
郝伟 2022/01/28
通过查询网上资料,本文主要参考文章Create A Windows Service In C#[1]进行安装。但是文章中仍然缺少一些细节,而导致的踩坑。因此,本文对这些内容进行记录。
AppDomain.CurrentDomain.BaseDirectory 来获得。使用服务安装使用 InstallUtil.exe 程序,命令格式为:InstallUtil.exe [服务程序路径],其中
InstallUtil.exe 有32位和64位两个版本,位置为:
C:\Windows\Microsoft.NET\Framework\v4.0.30319C:\Windows\Microsoft.NET\Framework64\v4.0.30319如 [服务程序路径] 为 C:\Services\FileUploadService.exe, 则命令为:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe C:\Services\FileUploadService.exe
注意:如果不存在InstallUtil的目录,则需要安装 .net framework,
为方便安装,编写了 ServiceInstall.bat 脚本,内容为:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe FileUploadService.exe
services.msc 启动Windows服务管理窗口;FileUploadService 服务,然后启动。安装和运行需要请注意以下内容:
[1] Create A Windows Service In C#, https://www.c-sharpcorner.com/article/create-windows-services-in-c-sharp/
[2] 使用C#创建Windows服务, https://www.cnblogs.com/cncc/p/7170951.html