设置SQLSERVER代理自动重启后,发现有时意外关闭后还是无法自动重启。
通过bat文件解决了该问题。
net session >nul 2>&1
if not "%errorLevel%" == "0" (
echo Oops: This tools must run with administrator permissions!
echo it will popup the UAC dialog, please click [Yes] to continue.
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "%*", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /b 2
)
@echo off
for /f "skip=3 tokens=4" %%i in ('sc query SQLSERVERAGENT') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
echo "SQL Server 代理 (MSSQLSERVER) 服务在运行。"
) else (
echo "SQL Server 代理 (MSSQLSERVER) 服务处理停止状态,准备启动……"
net start SQLSERVERAGENT
ping /n 3 127.1>nul
)
#pause>nul
通过windows自带任务计划程序,设置30分钟检查一次。