Start the bat script sharing of the sqlserver service, and sqlserverbat
I did not write this script. 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.
Copy codeThe Code is 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 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.