Solved

create batch file to stop and restart application and services

Posted on 2007-12-05
6
6,549 Views
Last Modified: 2010-08-05
Hi all,

I am not very good wioth DOS commands so here it is...

I need to create a bacth file that will perform the following actions in order

1.) Terminate an application such as MyApp.exe
2.) Stop MSSQL server
3.) Stop MSSQL Agent
4.) Wait 5 minutes
5.) Start MSSQL Server
6.) Start MSSQL Agent
7.0 Start MyApp.exe

Anyone have the necessary code to do this?
0
Comment
Question by:DLockwood
6 Comments
 
LVL 82

Accepted Solution

by:
oBdA earned 250 total points
Comment Utility
I don't have the exact service names at hand at the moment, but you can retrieve them in a command window using
net start
which shows all running services.
The SQL Agent should be stopped before the SQL server, it's dependent on the server
Basically it would look like this (the service names still need to be corrected); sleep.exe is part of the W2k3 ResKit (see link below):

taskkill /im "MyApp.exe"
net stop "MSSQL Agent"
net stop "MSSQL Server"
sleep 300
net stop "MSSQL Server"
net stop "MSSQL Agent"
start "" "MyApp.exe"

Windows Server 2003 Resource Kit Tools
http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
0
 
LVL 30

Assisted Solution

by:SteveGTR
SteveGTR earned 250 total points
Comment Utility
Could try this:
@echo off
 

net stop MSSQLServer

net stop SQLServerAgent
 

echo Waiting for 5 minutes

ping -n 301 127.0.0.1 > NUL
 

net start MSSQLServer

net start SQLServerAgent
 

start myapp.exe

Open in new window

0
 
LVL 15

Expert Comment

by:bpmurray
Comment Utility
Try something like the following:

          taskkill /IM MyApp.exe
          net stop "SQL Server"
          net stop "SQL Agent"
          ping 127.0.0.1 -n 301 -w 1000
          net start "SQL Agent"
          net start "SQL Server"
          MyApp.exe

The net stop/start commands may be slightly incorrect - if you do a "net start" from a command line, i.e. with no parameters, it'll list all the services available, including the correct names of the SQL services.



0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:DLockwood
Comment Utility
oBdA and SteveGTR - THANK YOU SO MUCH!!!!

I split the points because:

oBdA - Your answer is right on except for 2 parts which were supplied by SteveGTR.
1.) The net stop and start commands
2.) Sleep doesn't work in windows 2003.

So, when I combined the 2 response from you guys it worked PERFECT!!

Thanks again!

DL
0
 
LVL 30

Expert Comment

by:SteveGTR
Comment Utility
Mine also was deficient as I didn't add the taskkill statement :)
0
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
D'oh to the "net stop" instead of the "net start"; too much copy and paste, and that's when I noted that the agent should be stopped before the server.
But I mentioned how to get the sleep.exe, which is quite useful (not to mention the rest of the tools), and I prefer it to using ping.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now