Solved

create batch file to stop and restart application and services

Posted on 2007-12-05
6
6,551 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 83

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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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 83

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to update exe applicatio from internet ? 6 76
MacOS and programming in React 7 34
batch file problem 5 45
Removing line numbers from left column in config file 7 49
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
A short article about a problem I had getting the GPS LocationListener working.
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 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…

808 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