go windows-services

举报
Amrf 发表于 2020/02/26 21:25:36 2020/02/26
【摘要】 参考:http://blog.technololist.org/2017/06/09.htmlhttps://raw.githubusercontent.com/Technololist/golang-http-windows-service/master/websvc.gohttps://github.com/golang/sys/blob/master/windows/svc/examp...

参考:

http://blog.technololist.org/2017/06/09.html

https://raw.githubusercontent.com/Technololist/golang-http-windows-service/master/websvc.go

https://github.com/golang/sys/blob/master/windows/svc/example/service.go

https://godoc.org/golang.org/x/sys/windows/svc/example

https://github.com/golang/go/wiki/WindowsDLLs

https://www.jianshu.com/p/632ffea266f3

https://chai2010.cn/post/2018/window-service/

https://groups.google.com/forum/#!topic/golang-nuts/66RXNMQ1auU


  • bat检测服务是否存在和启动

@Echo Off
Set ServiceName=xxx

SC QUERY "%ServiceName%" > NUL
IF ERRORLEVEL 1060 GOTO MISSING
ECHO EXISTS
GOTO EXIST

:MISSING
ECHO SERVICE MISSING BEGIN INSTALLL IT
REM xxxx install

:EXIST

SC queryex "%ServiceName%"|Find "STATE"|Find /v "RUNNING">Nul&&(
    echo %ServiceName% not running 
    echo Start %ServiceName%

    Net start "%ServiceName%">nul||(
        Echo "%ServiceName%" wont start 
        exit /b 1
    )
    echo "%ServiceName%" started
    REM start chrome https://localhost:8088/
    exit /b 0
)||(
    echo "%ServiceName%" working
    REM start chrome https://localhost:8088/
    exit /b 0
)
  • bat设置服务自启动

 sc config “xxx” start= auto


【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。