This script is not written by me, I forget where I saw it, share it with you, because in my understanding technology is used to share, hope the original author see Don't mind.
1. Create a text and change the suffix name to. bat
2. Paste the bottom statement in, and then save it
Copy Code code as follows:
@echo off
for/f "Skip=3 tokens=4"%%i in (' sc query mssqlserver ') do set "zt=%%i" &goto:next
: Next
if/i "%zt%" = "RUNNING" (
Echo has discovered that the service is running, and starts to stop
net stop MSSQLServer
Echo SC config mssqlserver start = DISABLED Disable Service
) Else (
echo the service now handles the stop state and starts
Echo SC config mssqlserver start = Manual Set service manual
NET start MSSQLServer
)
Pause
The place to note is ' MSSQLServer ', which is the default instance name for SQL Server, and if you have multiple instances on your servers, you need to manually replace the service name in the script.