Solved

Error trapping in batch file - "net" command?

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
inactive users 13 93
RDP up only between 8am-13.00 pm ? 11 85
Event ID: 1008 / Source: Microsoft-Windows-Perflib 2 241
Connecting two servers 30 92
I guess it is not common knowledge to most Wintel engineers/administrators: If you have an SNMP-based monitoring system in your environment (and it's common to have SNMP or Syslog) it's reasonably easy to enable monitoring of the Windows Event logs,…
Many of us need to configure DHCP server(s) in their environment. We can do that simply via DHCP console on server or using MMC snap-in on each computer with Administrative Tools installed in a network. But what if we have to configure many DHCP ser…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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