DOS commands for stopping SQL services remotely and in sequence

  • How can one do this in DOS. ie. connect to a server on the network and stop a specific service.

    I need to be able to connect successively to several servers and manipulate services.

    I have sa privileges on the target machines.

    For example:

    (1) connect to server servA and stop the SQL Agent MSSQL$instA

    (2) connect to server servB and stop the SQL Agent MSSQL$instB

    How could I automate the sequence above?

    __________________________________________________________________________________
    SQL Server 2016 Columnstore Index Enhancements - System Views for Disk-Based Tables[/url]
    Persisting SQL Server Index-Usage Statistics with MERGE[/url]
    Turbocharge Your Database Maintenance With Service Broker: Part 2[/url]

  • You may try the following DOS command. But you have to make them workable on a remote server.

    at 6:30pm /EVERY:Monday,Tuesday,Wednesday,Thursday,Friday,Sunday "c:\stop.bat"

    at 6:30pm /EVERY:Monday,Tuesday,Wednesday,Thursday,Friday,Sunday "c:\start.bat"

    Where stop.bat

    net start mssqlserver

    start.bat

    net stop mssqlserver

  • SQL ORACLE (5/29/2008)


    You may try the following DOS command. But you have to make them workable on a remote server.

    at 6:30pm /EVERY:Monday,Tuesday,Wednesday,Thursday,Friday,Sunday "c:\stop.bat"

    at 6:30pm /EVERY:Monday,Tuesday,Wednesday,Thursday,Friday,Sunday "c:\start.bat"

    Where stop.bat

    net start mssqlserver

    start.bat

    net stop mssqlserver

    Thank you for the response.

    I actually found a way to manipulate services remotely through vb scripting and the WMI object:

    http://www.computerperformance.co.uk/vbscript/wmi_services.htm#Example_2_-_Script_to_Stop,_then_Start_a_Windows_Service_

    __________________________________________________________________________________
    SQL Server 2016 Columnstore Index Enhancements - System Views for Disk-Based Tables[/url]
    Persisting SQL Server Index-Usage Statistics with MERGE[/url]
    Turbocharge Your Database Maintenance With Service Broker: Part 2[/url]

  • You can use netsvc.exe to control services remotely. It's part of the Systems Management Server install or Windows Server Resource Kits.

    This KB article describes the tool in more detail:

    http://support.microsoft.com/kb/140378

    Kendal Van Dyke

    http://kendalvandyke.blogspot.com/

    Kendal Van Dyke
    http://kendalvandyke.blogspot.com/[/url]

  • Marios Philippopoulos (5/30/2008)


    SQL ORACLE (5/29/2008)


    You may try the following DOS command. But you have to make them workable on a remote server.

    at 6:30pm /EVERY:Monday,Tuesday,Wednesday,Thursday,Friday,Sunday "c:\stop.bat"

    at 6:30pm /EVERY:Monday,Tuesday,Wednesday,Thursday,Friday,Sunday "c:\start.bat"

    Where stop.bat

    net start mssqlserver

    start.bat

    net stop mssqlserver

    Thank you for the response.

    I actually found a way to manipulate services remotely through vb scripting and the WMI object:

    http://www.computerperformance.co.uk/vbscript/wmi_services.htm#Example_2_-_Script_to_Stop,_then_Start_a_Windows_Service_

    WMI is a great way to go. Wrapping it in a console app would likely give you what you need from the DOS environment.

    Otherwise - if you can get your hands on the Windows 2000 resource kit - you should be able to use the SC.exe utility. It's described here:

    http://www.cramsession.com/articles/get-article.asp?aid=858

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Thanks guys for your suggestions, I will have a look at the info provided.

    Matt, I was thinking of creating a .NET console app, but I'm not sure all machines of interest have .NET framework installed.

    What would be the advantage of running this as a console app as opposed to calling individual VBS scripts in a bat file?

    __________________________________________________________________________________
    SQL Server 2016 Columnstore Index Enhancements - System Views for Disk-Based Tables[/url]
    Persisting SQL Server Index-Usage Statistics with MERGE[/url]
    Turbocharge Your Database Maintenance With Service Broker: Part 2[/url]

  • Marios Philippopoulos (5/30/2008)


    Thanks guys for your suggestions, I will have a look at the info provided.

    Matt, I was thinking of creating a .NET console app, but I'm not sure all machines of interest have .NET framework installed.

    What would be the advantage of running this as a console app as opposed to calling individual VBS scripts in a bat file?

    All of the usual things:

    - better error trapping

    - compiled vs interpreted

    - actual typing of objects...

    (I'm not a huge fan of VBScript after having run into some rather horrible ones in the past)....

    I think you'll need the framework either way, unless you find some cute way to reference WMI without it....

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Thanks Matt, all you are saying makes a lot of sense.

    I'd also rather leverage the .NET framework.

    I'll give it a try...

    __________________________________________________________________________________
    SQL Server 2016 Columnstore Index Enhancements - System Views for Disk-Based Tables[/url]
    Persisting SQL Server Index-Usage Statistics with MERGE[/url]
    Turbocharge Your Database Maintenance With Service Broker: Part 2[/url]

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply