Batch .bat scripts remain the standard in many corporate Windows environments. Cerewro generates, debugs and optimizes them from the chat, adding conditional logic, loops and error handling.
Create a .bat script that checks if SQL Server service is running and if not, starts it and logs the event
@echo off
sc query MSSQLSERVER | find "RUNNING" > nul
if %errorlevel% neq 0 (
echo %date% %time% - SQL Server stopped, starting... >> C:\logs\services.log
net start MSSQLSERVER
echo %date% %time% - SQL Server started >> C:\logs\services.log
) else (
echo %date% %time% - SQL Server running >> C:\logs\services.log
)