Start the SQL Server service with bat

Source: Internet
Author: User
Tags mssqlserver

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.