C#制作Windows service服务系列一:制作一个可安装、可启动、可停止、可卸载的Windows service
系列一: 制作一个可安装、可启动、可停止、可卸载的Windows service(downmoon原创)
系列二:演示一个定期执行的windows服务及调试(windows service)(downmoon)
系列三: windows service系列三--制作可控制界面的windows service因为windows service 工作中最近开始频繁使用,而手工部署的方式,最好的是用BAT文件,可是程序要部署到别的服务器上时,就会发现路径是一个问题:当然也可以用全局变量来控制,这里不赘述。
给出一个手工部署的例子setupServer.bat
















unInstallServer.bat


















也可以同时判断两个以上的net FrameWork版本
这里要介绍的是一个完整的安装程序,所以服务本身就略去,如果有朋友需要学习,可以跟我联系3w@live.cn
好了,言归正传
假定 windows Service已写好,服务名为servTradeMatch2007,可执行文件名为TradeMatchService2007.exe

一、首先在解决方案中创建一个安装部署的项目,右键点击项目名称,在菜单中选择[添加]-->[项目输出],
在弹出的"添加项目输出组"窗口中,第一个下拉框会列出该解决方案中其他的项目,
选择需要制作安装的windows service项目,再选择主输出,点[确定]。如图:

依次在”目标计算机上的文件系统“--”应用程序文件夹“下添加以下四个文件
1、msiexec.exe
2、start.bat
3、stop.bat
4、主输出文件

其中msiexec.exe位于Windows\System32下
stopbat文件内容如下:



startbat文件内容如下:




在"用户的程序文件夹下",新建一文件夹”蔬菜网全文检索服务“,分别制作这前三个文件的快捷方式到这里

右键单击”卸载服务“(msexec.exe对应的快捷方式)
输入一串值

其中"/x "后面对应和数值来自
Setup_TradeMatchService2007.vdproj文件

OK ! 生成安装包,
别急,安装完后,windows service并没有安装成服务。
还必须在安装项目中添加自定义操作。右击安装项目->视图->自定义操作。如下图:分别添加自定义操作,在应用程序文件夹中选择刚才添加的主输出即可.


安装过程如下:




卸载:

【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步