Solved

Error trapping in batch file - "net" command?

Posted on 2006-11-22
5
414 Views
Last Modified: 2012-08-13
I've created a batch file to use the "net" command to stop a specific service, copy files, then start the service again.  If the service doesn't stop properly, for whatever reason, I would like the batch script to exit instead of continue on.  Anyone ever do this, or have any ideas?
0
Comment
Question by:lauren_it
5 Comments
 
LVL 95

Accepted Solution

by:
Lee W, MVP earned 63 total points
ID: 17999822
I would probably suggest using SC instead of the NET command... SC has better control over services.  Then you can test against error levels or even output of the SC command and continue accordingly.
0
 

Author Comment

by:lauren_it
ID: 17999939
Thanks, I'll look into the SC command.  For now I realized the simple "if ERRORLEVEL 1 goto" will work.  Maybe I'll get a little more fancy with it using SC in the future.
0
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 62 total points
ID: 18001128
Aswell as that and using sc as suggested (pipe sc query... into find to check the status) You can also use tasklist.exe against the exe task name still being in memeory though agreed an if errorlevel works fine - I sometimes use this with a list of exes for something like lotus domino when sometimes some of the service exes stay in memory.

net stop youprog
tasklist | find /I "yourprog.exe"
if errorlevel 1 goto end
xcopy .....
net start yourprog
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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