Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

create batch file to stop and restart application and services

Posted on 2007-12-05
6
Medium Priority
?
6,558 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 1000 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 1000 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn different types of Android Layout and some basics of an Android App.
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 fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

688 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