menu Chancel's blog
rss_feed
Chancel's blog
有善始者实繁,能克终者盖寡。

Windows配置后台自启服务

作者:Chancel Yang, 创建:2021-06-16, 字数:1022, 已阅:77, 最后更新:2024-03-10

Windows的后台服务常驻机制还是非常爽的,通常是流氓软件后台常驻,而我们自己的软件想配置后台自启却没有简洁的设置方式

Syncthing是一款同步文件工具,虽然有CLI版本,但我更喜欢命令行版本

CMD运行syncthing,CMD关闭就结束运行了,Syncthing如何常驻后台是个问题

计划任务是个不错的方法,但开机自启动需要重启验证(个人经验是不同版本的Windows计划人物可靠性不一致,不算是个非常保险的方法)

所以我还是更喜欢能把软件注册成服务的nssm工具,具体文档可以参考nssm的说明,文档短且易学,注册成系统服务之后也具备开机自启的特性

下载syncthing与nssm之后,可以使用如下指令注册成后台服务

Bash
.\nssm.exe install syncthing "C:\Programs\syncthing-windows-amd64-v1.13.1\syncthing.exe" '-home="C:\Programs\syncthing-windows-amd64-v1.13.1\config"'
.\nssm.exe start syncthing

具体操作例子(使用管理员身份的Powershell)

Bash
PS C:\Programs\nssm-2.24\win64> .\nssm.exe install syncthing "C:\Programs\syncthing-windows-amd64-v1.13.1\syncthing.exe" '-home="C:\Programs\syncthing-windows-amd64-v1.13.1\config"'
Service "syncthing" installed successfully!
PS C:\Programs\nssm-2.24\win64> .\nssm.exe start syncthing
syncthing: START: The operation completed successfully.

syncthing: START: The operation completed successfully. 提示就说明后台服务注册成功了


[[replyMessage== null?"发表评论":"发表评论 @ " + replyMessage.m_author]]

account_circle
email
web_asset
textsms

评论列表([[messageResponse.total]])

还没有可以显示的留言...
[[messageItem.m_author]] [[messageItem.m_author]]
[[messageItem.create_time]]
[[getEnviron(messageItem.m_environ)]]
[[subMessage.m_author]] [[subMessage.m_author]] @ [[subMessage.parent_message.m_author]] [[subMessage.parent_message.m_author]]
[[subMessage.create_time]]
[[getEnviron(messageItem.m_environ)]]