Solved

Error trapping in batch file - "net" command?

Posted on 2006-11-22
5
415 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

20 Experts available now in Live!

Get 1:1 Help Now