Solved

Error trapping in batch file - "net" command?

Posted on 2006-11-22
5
419 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
[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
5 Comments
 
LVL 96

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

So you have two Windows Servers and you have a directory/folder/files on one that you'd like to mirror to the other?  You don't really want to deal with DFS or a 3rd party solution like Doubletake. You can use Robocopy from the Windows Server 200…
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

695 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