Batch Files to Restart Services on Windows

October 09, 2002
coldfusion

I wrote some batch files today for restarting services on windows. The bat files can be used to restart ColdFusion MX or IIS services on Windows NT/2000/XP.

Batch File to restart ColdFusion MX

@echo off
REM - File: cfmxrestart.bat
REM - Description: Restart's ColdFusion MX Services
REM - Author: Pete Freitag
echo Restarting ColdFusion MX...
echo ======================================================
net stop "ColdFusion MX Application Server"
net stop "ColdFusion MX ODBC Agent"
net stop "ColdFusion MX ODBC Server"
net start "ColdFusion MX Application Server"
net start "ColdFusion MX ODBC Agent"
net start "ColdFusion MX ODBC Server"
echo ======================================================
echo ColdFusion MX Restarted

Batch file to restart IIS

@echo off
REM - File: iisrestart.bat
REM - Description: Restart's IIS (Web, FTP, SMTP)
REM - Author: Pete Freitag
REM - ADD REM comments if you don't want to restart any
REM - of Services
echo Restarting IIS...
echo ======================================================
net stop "World Wide Web Publishing Service"
net start "World Wide Web Publishing Service"
net stop "FTP Publishing Service"
net start "FTP Publishing Service"
net stop "Simple Mail Transport Protocol (SMTP)"
net start "Simple Mail Transport Protocol (SMTP)"
echo ======================================================
echo IIS Restarted
Bat files are handy because you can restart multiple services with one command. You can either double click the bat file to run it, schedule it, or throw it in c:\windows\system32 and then run it from anywhere in the command prompt or (Start->Run)


Related Entries

13 people found this page useful, what do you think?

Comments

Anybody can help me to write a bat file to backup some data from c:\program files\winair to Home directory H:\user name. I knew a little bit but not so good. Please give me some detailed information.
I know it is not safest thing to do, but is there a simple way to execute a batch file from a web page ? I want to do this for some other APIs that crash occasionally. Thanks.
I cannot run any of my programs because I have lost my MICROSETUPLIB.BAT file can you help please e-mail me ! Thanks Jason
while i run your iis restaTHE Specified service does not exit as an installed service.
Why don't you check if what you post actually works before putting it online? The MS knowledgebase specifically states that: "NOTE: For each service, there is also a DisplayName value, which is the name listed in the Services applet in Control Panel and in the messages displayed after the NET STOP and NET START commands are run. However, these Display Names cannot be used as a parameter with the NET STOP and NET START commands." http://support.microsoft.com/kb/236166 Please chekc your facts before posting such nonsense.
@echo off REM - File: iisrestart.bat REM - Description: Restart's IIS (Web, FTP, SMTP) REM - Author: Pete Freitag REM - ADD REM comments if you don't want to restart any REM - of Services echo Restarting IIS... echo ====================================================== net stop W3SVC net start W3SVC echo ====================================================== echo IIS Restarted REM - File: iisrestart.bat REM - Description: Restart's IIS (Web, FTP, SMTP) REM - Author: Pete Freitag REM - ADD REM comments if you don't want to restart any REM - of Services echo Restarting SQL... echo ====================================================== net stop "SQL Server Agent (MSSQLSERVER)" net stop MSSQLSERVER net start MSSQLSERVER net start "SQL Server Agent (MSSQLSERVER)" echo ====================================================== echo SQL Restarted
Regarding Sander's comment, Pete seems to have taken some time to format and comment the batch files, yet he used the wrong service name. I found that amusing. Anyway, I agree with Sander. Please test everything before you post it. It's also the responsibility of the visitors to review the syntax instead of blindly using everything as is.
Hi Friends, Can you people give me some idea how to monitor the widows services.. say... IISadmin service status thru batch file and send an email notification if it is down. please help me Kish
how do you schedule it?
Google is your friend. Go look it up.
Here is a shutdown for ColdFusion 8

@ECHO off
title Shutdown process for ColdFusion 8 and Internet Services.

:restart
c:
cd\
cls

ECHO.
ECHO ==========================================
ECHO.
ECHO Shutdown process for ColdFusion 8.
ECHO Written by: Scott Sandbakken.
ECHO.
ECHO Use at your own risk.
ECHO No warrenty expressed or implied.
ECHO.
ECHO ==========================================
ECHO.


:start

set gohere == 'start'

ECHO.
ECHO 1. Shut down Internet Services
ECHO 2. Start Internet Services
ECHO 3. Restart Internet Services
ECHO X. Exit
ECHO.

set choice=
set /p choice=Please make a selection:

if not '%choice%'==' set choice=%choice:~0,1%
if '%choice%'=='1' goto one
if '%choice%'=='2' goto two
if '%choice%'=='3' goto three
if '%choice%'=='q' goto quit
if '%choice%'=='Q' goto quit
if '%choice%'=='x' goto exit
if '%choice%'=='X' goto exit

ECHO "%choice%" is not valid please try again
ECHO.

goto start

:one

ECHO.
ECHO Stopping ColdFusion 8 Services
ECHO.

NET STOP "ColdFusion 8 .NET Service"
NET STOP "ColdFusion 8 ODBC Agent"
NET STOP "ColdFusion 8 ODBC Server"
NET STOP "ColdFusion 8 Search Server"
NET STOP "ColdFusion 8 Application Server"

ECHO.
ECHO Stopping Internet Services
ECHO.

NET STOP "Simple Mail Transfer Protocol (SMTP)"
NET STOP "World Wide Web Publishing"
NET STOP "IIS Admin"

ECHO.
ECHO \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
ECHO ColdFusion 8 and Internet Services have been shut down.
ECHO ////////////////////////////////////
ECHO.

goto start

:two

ECHO.
ECHO Starting Internet services
ECHO.

NET START "IIS Admin"
NET START "Simple Mail Transfer Protocol (SMTP)"
NET START "World Wide Web Publishing"

ECHO.
ECHO Starting ColdFusion 8 Services
ECHO.

NET START "ColdFusion 8 Application Server"
NET START "ColdFusion 8 .NET Service"
NET START "ColdFusion 8 ODBC Server"
NET START "ColdFusion 8 ODBC Agent"
NET START "ColdFusion 8 Search Server"

ECHO.
ECHO \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
ECHO ColdFusion 8 and Internet Services have been started.
ECHO ////////////////////////////////////
ECHO.

goto start

:three

ECHO.
ECHO Stopping ColdFusion 8 and Internet Services
ECHO.

NET STOP "ColdFusion 8 .NET Service"
NET STOP "ColdFusion 8 ODBC Agent"
NET STOP "ColdFusion 8 ODBC Server"
NET STOP "ColdFusion 8 Search Server"
NET STOP "ColdFusion 8 Application Server"

NET STOP "Simple Mail Transfer Protocol (SMTP)"
NET STOP "World Wide Web Publishing"
NET STOP "IIS Admin"

ECHO.
ECHO Starting ColdFusion 8 and Internet Services
ECHO.

NET START "IIS Admin"
NET START "Simple Mail Transfer Protocol (SMTP)"
NET START "World Wide Web Publishing"

NET START "ColdFusion 8 Application Server"
NET START "ColdFusion 8 .NET Service"
NET START "ColdFusion 8 ODBC Server"
NET START "ColdFusion 8 ODBC Agent"
NET START "ColdFusion 8 Search Server"

ECHO.
ECHO \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
ECHO ColdFusion 8 and Internet Services have been restarted.
ECHO ////////////////////////////////////
ECHO.

goto start



:exit
exit

:quit
cls
cmd
goto restart
This is a bit old but I need a favor.

How can I use it to restart services on a remote computer?
This is a bit old but I need a favor.

How can I use it to restart services on a remote computer?
An easier solution would be to use something like Service Hawk.
Use the SC command. This is way better as the NET command is. in a CMD box type sc /?.
i like it, worked like a charm.
i actually used cfexecute to run it
but if you have cf hanging you might want to have a php script execute it, or some other language
echo off

start google.be ffs
lazy..
I used this script to start wampmysqld service on windows vista and it don't work to me
can someone help me?

ps wampmysqld is installed with wamp
Hi There. Is there also a batch to stop and restart Coldfusion 9 services?
Antoine -

You really just need to substitute in the service name from Services, for instance "ColdFusion 9 Application Server"

For CF8 I use this:

@echo off
echo Restarting ColdFusion 8...
echo ======================================================
net stop "ColdFusion 8 Application Server"
choice /T 20 /D y
net start "ColdFusion 8 Application Server"
echo ======================================================
echo ColdFusion 8 Restarted
well i guess my copy/paste carriage returns didn't come through properly.
let's try again

@echo off echo Restarting ColdFusion 8...
echo ======================================================
net stop "ColdFusion 8 Application Server"
choice /T 20 /D y
net start "ColdFusion 8 Application Server"
echo ======================================================
echo ColdFusion 8 Restarted

(if this fails to post properly, i think you can figure out where the breaks go)
To restart IIS, the most simple way is: iisreset
cheers,

Post a Comment




  



Spell Checker by Foundeo

Recent Entries



foundeo


did you hack my cf?