473,326 Members | 2,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Batch Scripting Help

2
Hi all,

I'm writing this batch script to start/stop some windows services using a combination of net start/stop and sc.exe. Now I need to do some verification on it, command 2 can only run when command 1 runs successfully. So let's say I issue

sc start WinService01

If this service starts successfully it should run WinService02. If it doesn't run then goto WinService05 or something like that.

I've played around with:
Expand|Select|Wrap|Line Numbers
  1. :begin
  2. @echo off
  3. sc start WinService01
  4. if errorlevel 1 goto end
  5. echo Success
  6. :end
  7. echo Failed
  8.  
In this snippet when the service runs fine it will display Success, no problem. But when the service fails to run it will display Failed AND Success.

What am I missing? Or if you have a better script I'd appreciate it.

Thanks in advanced!
Jan 24 '08 #1
1 1317
MindBender77
234 100+
Hi all,

I'm writing this batch script to start/stop some windows services using a combination of net start/stop and sc.exe. Now I need to do some verification on it, command 2 can only run when command 1 runs successfully. So let's say I issue

sc start WinService01

If this service starts successfully it should run WinService02. If it doesn't run then goto WinService05 or something like that.

I've played around with:
Expand|Select|Wrap|Line Numbers
  1. :begin
  2. @echo off
  3. sc start WinService01
  4. if errorlevel 1 goto end
  5. echo Success
  6. :end
  7. echo Failed
  8.  
In this snippet when the service runs fine it will display Success, no problem. But when the service fails to run it will display Failed AND Success.

What am I missing? Or if you have a better script I'd appreciate it.

Thanks in advanced!
You could try something like this:
Some executables can return negetive numbers as error levels
Expand|Select|Wrap|Line Numbers
  1. :begin
  2. @echo off
  3. sc start WinService01
  4. IF %ERRORLEVEL% NEQ 0 ... goto end 
  5. echo Success
  6. :end
  7. echo Failed
  8.  
Jan 25 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Moosebumps | last post by:
So, after reading some messages about os.system, and looking at the popen stuff and trying it a bit, I still have not found a way to keep a command window open for several commands (on Windows...
0
by: SkySea | last post by:
Hi! Any help on this would be appreciated... In an HTML document that lists instructions on installing some software, there's a point where a DOS batch file needs to be run in order to copy...
9
by: Doug at SAU | last post by:
I need to run a batch file on a remote machine from an ASP page. I dummied up a test ASP page as follows: <% Set WshShell = Server.CreateObject("Wscript.Shell") wshshell.run...
8
by: Sir_Scriptor | last post by:
Hi, I am trying to understand Batch files for logging Text. I have a general understanding, but I am little lost on some of the command strings I keep seeing. I went out and Bought Microsoft Windows...
6
by: viki | last post by:
Hi, I want to run the batch file from the client side. I was able to do it in the server side by using process. But i want to run from the client side , like we do in asp using...
4
by: mitymouse | last post by:
I am fairly familiar with scripting dos commands and that's about it. I remember some syntax and whatnot from a few programming classes I've taken but I don't remember any of the modules or functions...
1
benchpolo
by: benchpolo | last post by:
I'm not sure if this is the right section to post my question regarding FTP Batch scripting. Question? I have multiple textfiles where the filename is dynamically changing daily. For example, ...
2
by: Sm00th | last post by:
Hi all, Need help again in batch scripting. I need to create a command line script to launch an .exe file, but this .exe launches a window instead of a command prompt, and in this window you have...
5
by: veeraiah | last post by:
Hi, I am new to PERL Scripting, i need your help with one of the problem i am having. I am having a PERL Script which has two variables $CurMon and $PriorMon. a Windows batch script calls this...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.