Solved

Error trapping in batch file - "net" command?

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

820 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