Batch Files to Restart Services on Windows

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?

 Download FuseGuard WAF for ColdFusion

Trackbacks

Trackback Address: 87/4EB786F8293CEA1417A5EB32BDD7BD87

Comments

On 01/14/2004 at 3:12:11 PM EST ging wrote:
1
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.

On 03/29/2004 at 10:19:26 PM EST Kirk Mower wrote:
2
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.

On 12/16/2004 at 11:25:34 AM EST Jason FAWcett wrote:
3
I cannot run any of my programs because I have lost my MICROSETUPLIB.BAT file can you help please e-mail me ! Thanks Jason

On 06/22/2007 at 1:24:09 PM EDT SREE wrote:
4
while i run your iis restaTHE Specified service does not exit as an installed service.

On 10/25/2007 at 10:17:55 AM EDT Sander wrote:
5
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.

On 04/02/2008 at 5:24:15 PM EDT DallasPartners.com wrote:
6
@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

On 09/24/2008 at 11:55:35 AM EDT Mel K wrote:
7
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.

On 01/22/2009 at 8:53:33 AM EST kishore wrote:
8
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

On 01/25/2009 at 1:37:32 AM EST Anonymous wrote:
9
how do you schedule it?

On 02/23/2009 at 10:58:41 AM EST ACID wrote:
10
Google is your friend. Go look it up.

On 11/16/2009 at 12:28:41 PM EST Scott Sandbakken wrote:
11
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

On 01/06/2010 at 8:43:35 AM EST Ayham wrote:
12
This is a bit old but I need a favor.

How can I use it to restart services on a remote computer?

On 01/06/2010 at 8:43:36 AM EST Ayham wrote:
13
This is a bit old but I need a favor.

How can I use it to restart services on a remote computer?

On 02/03/2010 at 6:47:51 PM EST Ed wrote:
14
An easier solution would be to use something like Service Hawk.

On 02/12/2010 at 7:07:02 AM EST Danny wrote:
15
Use the SC command. This is way better as the NET command is. in a CMD box type sc /?.

On 04/13/2010 at 12:54:44 AM EDT joe wrote:
16
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

On 04/29/2010 at 1:47:42 PM EDT Anonymous wrote:
17
echo off

start google.be ffs lazy..

On 08/07/2010 at 8:56:39 AM EDT Anonymous wrote:
18
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

On 09/14/2011 at 11:18:32 AM EDT Antoine wrote:
19
Hi There. Is there also a batch to stop and restart Coldfusion 9 services?

On 09/16/2011 at 4:34:52 PM EDT joe wrote:
20
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

On 09/16/2011 at 4:37:23 PM EDT joe wrote:
21
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)

On 06/25/2012 at 1:06:55 PM EDT MT wrote:
22
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?