使用WinSW.NET部署Window服务
1.网上下载WinSw.NET4.exe
配置文件内:
<configuration>
<!-- ID of the service. It should be unique accross the Windows system-->
<!-- id,name,修改成对应服务的名称-->
<id>ServerName</id>
<!-- Display name of the service -->
<name>ServerName</name>
<!-- Service description -->
<!-- 注释信息-->
<description>descMessage</description>
<!--服务的工作目录,可自行定义 %BASE%\ 指主目录-->
<env name="WORKING_DIR" value="%BASE%\Service" />
<!--指调用dotnet.exe所在路径-->
<env name="EXE_FILE" value="C:\Program Files\dotnet\dotnet.exe" />
<!-- Path to the executable, which should be started -->
<executable>%EXE_FILE%</executable>
<!--对应服务的dll文件名称-->
<arguments>Server.dll</arguments>
<!-- 启动参数 可自行定义其他的命令-->
<!-- <startarguments></startarguments> -->
<!-- 停止命令 -->
<!-- <stopexecutable>%WORKING_DIR%\%EXE_FILE%</stopexecutable>
<stoparguments>-s stop</stoparguments> -->
<!-- 表示启动时需要填写账号密码 -->
<!--
<serviceaccount>
<domain>YOURDOMAIN</domain>
<user>useraccount</user>
<password>Pa55w0rd</password>
<allowservicelogon>true</allowservicelogon>
</serviceaccount>
-->
<!-- 表示第一次启动延迟10s 第二次延迟20s ... -->
<onfailure action="restart" delay="10 sec"/>
<onfailure action="restart" delay="20 sec"/>
<onfailure action="restart" />
<resetfailure>1 hour</resetfailure>
<!-- 工作目录 -->
<workingdirectory>%WORKING_DIR%</workingdirectory>
<!-- 优先级 : Normal, Idle, High, RealTime, BelowNormal, AboveNormal -->
<priority>Normal</priority>
<!-- 服务停止超时时间 -->
<stoptimeout>15 sec</stoptimeout>
<!-- 是否先关主线程(WinSW) -->
<stopparentprocessfirst>false</stopparentprocessfirst>
<!--启动模式 -->
<startmode>Automatic</startmode>
<!-- 延迟启动 -->
<!--<delayedAutoStart/>-->
<!-- 依赖关系 -->
<!--
<depend>Eventlog</depend>
<depend>W32Time</depend>
-->
<!-- 未知,不要改 -->
<waithint>15 sec</waithint>
<sleeptime>1 sec</sleeptime>
<!-- 是否能跟桌面通讯 -->
<!-- <interactive/> -->
<!-- 日志的存储路径 -->
<logpath>%BASE%\logs</logpath>
<log mode="roll-by-size-time">
<sizeThreshold>10240</sizeThreshold>
<pattern>yyyyMMdd</pattern>
<autoRollAtTime>00:00:00</autoRollAtTime>
<zipOlderThanNumDays>7</zipOlderThanNumDays>
<zipDateFormat>yyyyMM</zipDateFormat>
</log>
</configuration>
最后在WinSW.net的文件下使用管理员身份进入命令窗口,通过命令注册服务: WinSW.NET.exe install
WinSW.NET.exe uninstall : 卸载服务

浙公网安备 33010602011771号