BAT 实现服务自动开启关闭

@echo off
color 0B
::判断服务是否被禁用,如果被禁用就设置为自动
::wmic service where "name="MSSQL$SQL2005" and startmode="disabled"" call changestartmode
::判断服务是否启动,如果未启动就启动此服务
::wmic service where "name="MSSQL$SQL2005" and state="stopped"" call startservice
net start >service.txt
find /i service.txt "SQL Server (SQL2005)"
if errorlevel 1 goto start
if errorlevel 0 goto stop
:start
net start MSSQL$SQL2005
goto success
:stop
net stop MSSQL$SQL2005
goto end
:success
::net start
@echo 服务开启成功,谢谢使用!
:end
del "service.txt"
@pause>nul
exitBAT 实现服务自动开启关闭

猜你喜欢

转载自tiztm.iteye.com/blog/783450
bat