用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= "%~dp0SSFCJS.exe /S" type= own start= demand obj= localsystem Displayname= "SService"
sc start "SService"
pause
goto end

  

原文地址:https://www.cnblogs.com/yinxuejunfeng/p/14371653.html