473,797 Members | 2,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Batch Scripting Help

2 New Member
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 1334
MindBender77
234 New Member
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
3506
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 2000/XP), while seeing the normal output in a command window. All I want to do is do what a batch file does, but I want to actually have functions and associative arrays and all the other niceties of python. What's the deal with that? I thought...
0
10154
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 files from the CD to the hard drive. Given that CD drives can have various names, I wanted to run the batch file using relative paths. The problem is, the DOS window that opens to run the batch file can leave the command prompt at any location . So...
9
8848
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 "c:\inetpub\wwwroot\logasp\getdr.bat > c:\tstlog.txt" %> the batch file is as follows:
8
16664
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 Scripting, and Command Line books. I am trying those command lines, and I am getting error messages. I guess you can’t run VBS command lines, and Batch files together. I am also having a problem trying to get script-o-matic ver2.0 to work. I hear in...
6
9472
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 createobject("wscript.shell"). I tried the same code by using the html control and the client side code, but it gives me the error in createobject statement. Is there any way to run the batch files in the client, could some one help me with the code....
4
4719
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 for VB at all. Goal: I need to set persistent routes for 2 ip address on a VPN that has a dynamic gateway each time it connects. I am almost positive I can't script this with standard dos commands so I am wondering if VB will let me do this...
1
3854
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, Member_20071014.txt, Member_20071015.txt, Member_20071016.txt. These files are produced daily, how do I write a batch script that will pick-up the current date text file to upload on an FTP site. I tried to research windows batch file scripting,...
2
2947
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 to login and click some buttons before it actually do its stuff. How can I pass keystroke parameters just by using the command line? Here's what it's supposed to do: 1) Run winprogram.exe 2) Enter password 3) Tab 4) Enter 5) delay 5 seconds
5
5914
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 PERL Script. I want to return the values of the these two variables to the windows batch script. Can i do this? Please give me some suggestions. Thank You Chow
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9536
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9063
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4131
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.