用bat命令创建Windows服务,存在则启动

判断服务是否存在,存在就直接启动,不存在则创建后启动,引号里的内容替换成自己的服务名即可

 

@echo off
sc query SService |findstr /i "STATE">nul
if not errorlevel 1 (goto exist) else goto notexist

:exist
sc start "SService"
pause
goto end

:notexist
sc create "SService" binpath= "%~dp0\SSFCJS.exe /S" type= own start= demand obj= localsystem Displayname= "SService"
sc start "SService"
pause
goto end

  

posted @ 2021-02-04 11:28  饮雪俊枫  阅读(807)  评论(0编辑  收藏  举报