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)

cfobjective pre-conf training

Related Entries

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

WAF for CF

Trackbacks

Trackback Address: 87/4EB786F8293CEA1417A5EB32BDD7BD87

Comments

On 01/14/2004 at 1: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 8: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 9: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 11:24:09 AM EDT SREE wrote:
4
while i run your iis restaTHE Specified service does not exit as an installed service.

On 10/25/2007 at 8: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 3: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 9: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 6: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/24/2009 at 11:37:32 PM EST Anonymous wrote:
9
how do you schedule it?

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

On 11/16/2009 at 10:28:41 AM 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 6: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 6: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 4:47:51 PM EST Ed wrote:
14
An easier solution would be to use something like Service Hawk.

On 02/12/2010 at 5: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 /?.

Post a Comment




  



Spell Checker by Foundeo

Recent Entries





Basecamp
pfreitag on twitter