Solved

create batch file to stop and restart application and services

Posted on 2007-12-05
6
6,557 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 250 total points
ID: 20414449
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
ID: 20414453
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
ID: 20414541
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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:DLockwood
ID: 20415205
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
ID: 20415226
Mine also was deficient as I didn't add the taskkill statement :)
0
 
LVL 85

Expert Comment

by:oBdA
ID: 20415286
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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Simple Linear Regression

626 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