Go Back   TechArena Community > Software > Windows Software
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , , , , ,

Sponsored Links



Start and Stop Services in a single batch file?

Windows Software


Reply
 
Thread Tools Search this Thread
  #1  
Old 20-01-2010
Dilbert's Avatar
Member
 
Join Date: Aug 2006
Posts: 196
Start and Stop Services in a single batch file?

Hello Friends,
I was wondering, that is it possible to start or stop a service using a single batch file.?? Can I use the "if" type structure to do the both services in one batch file.?? I am very new to this batch files, so hoping that someone can help me out.! Please help me as soon as possible.!
__________________
We endorse perversion and call it an alternative lifestyle
We kill our unborn and call it choice
We neglect to discipline our children and call it building self-esteem
We pollute the air with profanity and pornography and call it freedom of expression

Reply With Quote
  #2  
Old 20-01-2010
opaper's Avatar
Member
 
Join Date: May 2008
Posts: 2,362
Re: Start and Stop Services in a single batch file?

You can create the batch files to schedule all sorts of things from Defragging drives, to performing backups, stopping services on servers, etc. The batch files are made like the DOS commands. In other words, you can say that the
batch file is made of the exact same commands. Here is an example :
Code:
h:
cd\retros~1
copy *.* c:\retrocpy /V/Y
You will have to open the Notepad which is a simple text editor. Type the commands that has been mentioned above into Notepad and then save the code. Also make sure that while saving the text file you will have to save it as .bat. You can do this by selecting Type as the 'All Files'. Hope that you will get some needful help from this post.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #3  
Old 20-01-2010
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,976
Re: Start and Stop Services in a single batch file?

I think that you can use the following code for Start and Stop Services in a single batch file. You will have to create a batch file as mentioned by the 'opaper'. The following coding you will have to save in the Notepad and then save it as Batch file. Here is the coding
Code:
IF "service"==stopped "NET START 'service'"

IF "service"==started "NET STOP 'service'"
Reply With Quote
  #4  
Old 20-01-2010
Member
 
Join Date: May 2008
Posts: 1,990
Re: Start and Stop Services in a single batch file?

Instead of using the
Code:
IF "service"==stopped "NET START 'service'"
IF "service"==started "NET STOP 'service'"
you can also use the following
Code:
NET START "service" || NET STOP "service"
The symbol "||" is used when you have to redirect to run the second command if the first fails. So there is no major difference in between the two coding.
Reply With Quote
  #5  
Old 20-01-2010
absolute55's Avatar
Member
 
Join Date: Nov 2005
Posts: 1,238
Re: Start and Stop Services in a single batch file?

You can also use the following code.
Code:
sc query service | findstr /i running | if "%errorlevel%"=="0" (sc stop service) else (sc start service)
Now when the %errorlevel% is not 0, it means that the search string wasn't found in the output of the command and that doesn't mean that the command failed. Many think that when the %errorlevel% is not 0 means that there is some error in the coding so the command has failed. I would like to tell you that this is not the fact.
Reply With Quote
Reply

  TechArena Community > Software > Windows Software


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Start and Stop Services in a single batch file?"
Thread Thread Starter Forum Replies Last Post
Windows XP - Network connection services failed to start...Error 2: File cannot be found jayarect Operating Systems 1 4 Weeks Ago 07:05 AM
How to Start and Stop Gnome GUI Services Lilija Operating Systems 4 12-11-2010 07:30 AM
How to Win XP services Start, Stop, Manual, Pause and Resume RasMus Operating Systems 3 07-07-2009 09:27 AM
VBScript that will stop then start two services and pop up a message box afterwards Spin Windows Server Help 5 24-04-2009 05:45 AM
win2ksp4 - cannot stop/start services, install/uninstall software,use Internet Explorer Jim Window 2000 Help 12 23-08-2005 01:29 AM


All times are GMT +5.5. The time now is 08:16 PM.