自己写的一个bat。查c#执行批处理的方法。
@echo off
color 0B
::判断服务是否被禁用,如果被禁用就设置为自动...
::wmic service where "name="MSSQL$ASTAR7" and startmode="disabled"" call changestartmode
::判断服务是否启动,如果未启动就启动此服务...
::wmic service where "name="MSSQL$ASTAR7" and state="stopped"" call startservice
net start >d:\service.txt
find /i d:\service.txt "SQL Server (ASTAR7)"
if errorlevel 1 goto start
if errorlevel 0 goto stop
:start
net start MSSQL$ASTAR7
goto success
:stop
net stop MSSQL$ASTAR7
goto end
:success
::net start
@echo 服务开启成功...
:end
del "d:\service.txt"