Start the SQL Server service with bat
I declare that this SQL Server Service script was not written by me. I forgot where I saw it. I will share it with you here, because in my understanding, the technology is used for sharing, don't mind if the author sees it.
1. Create a text file and change the suffix to. bat.
2. paste the following statement and save it.
@ 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 found that the service is running and stops
Net stop MSSQLSERVER
Echo SC config MSSQLSERVER start = DISABLED disable the service
) Else (
Echo the service is in the stopped processing status and starts to start
Echo SC config MSSQLSERVER start = Manual set Manual Service
Net start MSSQLSERVER
)
Pause
Note that 'sqlserver' is the default Instance name of sqlserver. If you have multiple instances on your server, you need to manually Replace the service name in the script.
This article permanently updates the link address: