Tuesday, 28 December 2010

Start and stop batchfile services via a batchfile

Case
Constantly running all Microsoft SQL Services on your development desktop/laptop could be a little too much. Especially when you're not developing, but starting and stopping via the control panel is tiresome...

Solution
You can stop/start a service via the command (or even better, put it in a batchfile):
Syntax
      NET START [service]
      NET STOP [service]
      NET PAUSE [service]
      NET CONTINUE [service] 
   
Key
   service : The service name as shown in Control Panel, Services

Apparently it does not matter whether you use the Service name or the Display name. 
Service name or Display name















Start batchfile SQL 2005:
@ECHO OFF
NET START "SQL Server (MSSQLSERVER)"
NET START "SQL Server Agent (MSSQLSERVER)"
NET START "SQL Server Integration Services"
NET START "SQL Server Analysis Services (MSSQLSERVER)"
NET START "SQL Server Reporting Services (MSSQLSERVER)"

Stop batchfile SQL 2005:
@ECHO OFF
NET STOP "SQL Server (MSSQLSERVER)"
NET STOP "SQL Server Agent (MSSQLSERVER)"
NET STOP "SQL Server Integration Services"
NET STOP "SQL Server Analysis Services (MSSQLSERVER)"
NET STOP "SQL Server Reporting Services (MSSQLSERVER)"



Start batchfile SQL 2008:
@ECHO OFF
NET START "MSSQLSERVER"
NET START "SQL Server Agent (MsSqlServer)"
NET START "SQL Server Integration Services 10.0"
NET START "MSSQLServerOLAPService"
NET START "ReportServer"

Stop batchfile SQL 2008:
@ECHO OFF
NET STOP "MSSQLSERVER"
NET STOP "SQL Server Agent (MsSqlServer)"
NET STOP "SQL Server Integration Services 10.0"
NET STOP "MSSQLServerOLAPService"
NET STOP "ReportServer"

Note: It works the same for SQL 2012. Only the SSIS name has been changed to SQL Server Integration Services 11.0 and the rest of the names depend on the instance name you choose.

If you try to start a service that is already running you will get an error message like:
"The requested service has already been started. More help is available by typing NET HELPMSG 2182"

If you're running Windows Vista or Windows 7, your will have to start the batch file as an administrator or disable the User Account Control (UAC).
User Account Control (UAC)

6 comments:

  1. Hi,
    i was testing the script with some problems for to stop sql server agent, for me is better change the order.First NET STOP Sql Server Agent.

    @ECHO OFF
    NET STOP "SQL Server Agent (MSSQLSERVER)"
    NET STOP "SQL Server Integration Services"
    NET STOP "SQL Server Analysis Services (MSSQLSERVER)"
    NET STOP "SQL Server Reporting Services (MSSQLSERVER)"
    NET STOP "SQL Server (MSSQLSERVER)"

    ReplyDelete
    Replies
    1. No Need To Send The First Line To The End , Just Stop The Agent First:

      @ECHO OFF
      NET STOP "SQL Server Agent (MsSqlServer)"
      NET STOP "MSSQLSERVER"
      NET STOP "SQL Server Integration Services 11.0"
      NET STOP "MSSQLServerOLAPService"
      NET STOP "ReportServer"

      Tested On MS SQL 2012 !!!!

      Delete
  2. Thanks

    Been through lots of sites and none made it as easy as you did. This works perfecly and will save my client lots of time as this process is done manually at the moment.

    regards
    Thivi

    ReplyDelete
  3. i want to stop one job only.. i don't want stop all service... please advice...

    ReplyDelete
    Replies
    1. A SQL Server Agent job can be stopped with a stored procedure: sp_stop_job

      Delete
  4. Hi

    I found the Intergration service name has changes again for SQL server 2012 sp1.
    NET STOP "SQL Server Integration Services 12.0"

    ReplyDelete

Please use the SSIS MSDN forum for general SSIS questions that are not about this post. I'm a regular reader of that forum and will gladly answer those questions over there.

All comments are moderated manually to prevent spam.

Related Posts Plugin for WordPress, Blogger...