Restarting Web Services and Scheduled Tasks with a Batch File
Suitable
This Article Was previously Published Under Q194916
Summarythis Article Describes How To Shut Down The Internet Information Server (IIS) Services While Other Scheduled Tasks Are Running.
MORE INFORMATIONThe following instructions and batch file allow you to schedule IIS to restart on a daily basis at 1:00 A.M. It will also keep a log to show when the services were stopped and started in your% SystemRoot% folder. By modifying the Remark (REM) Sections of the Batch File You Can Specify Other Commands To Run While IIS Is Stopped.
Log on to the windows nt computer as an administrator. Make su consisting the task scheduler service is set to automatically run by performing the following steps:
Click the Start button, point to Settings, click Control Panel, and then double-click Services. Scroll to "Task Scheduler." If the status does not say running, then click the Start button. Click the Startup button. Make sure the Startup Type is set to automatic, and then click OK. Click Close To EXIT The Services Dialog Box. Open a Command Prompt Session and Type The Following Command: At 1:00 AM / EVERY: M, T, W, TH, F, S, Su "restart.bat" Save the Following Text As A Batch File Named Restart.bat in Your Path: @echo off CLS Echo Restart - A Restart Utility for IIS Web Services. Echo June 1998, Microsoft Corporation. Echo ***** ********************************** >>% SystemRoot% / Restart.log echo stop date / time: >>% systemroot% / restart.log echo. | DATE | FIND / I "CURRENT" >>% systemroot% / restart.log echo. | Time | Find / I "current" >>% systemroot% / restart.log echo . >>% systemroot% / restart.log echo stopping web services ... echo. Set msftpsvc = 0 set nntpsvc = 0 set smtpsvc = 0 set w3svc = 0 set broksvc = 0 set ldaps VC = 0 set msgbldsvc = 0 set iiserror = 0: MSFTPSVC NET Start | Find / I "FTP Publishing Service"> NUL IF Errorlevel == 1 goto nntpsvc set msftpsvc = 1: nntpsvc net start | Find / i "Microsoft NNTP Service" > NUL IF ErrorLevel == 1 Goto SMTPSVC SET NNTPSVC = 1: SMTPSVC Net Start | Find / I "Microsoft SMTP Service"> NUL IF Errorlevel == 1 GOTO W3SVC SET SMTPSVC = 1: W3SVC Net Start | Find / I "World Wide Web Publishing Service "> NUL if Errorlevel == 1 goto brokersvc set w3svc = 1: broksvc net start | Find / i" site server automation service "> NUL if errorlevel ==
1 goto LDAPSVC set BROKSVC = 1: LDAPSVC net start | find / i "Site Server LDAP Service"> NUL if errorlevel == 1 goto MSGBLDSVC set LDAPSVC = 1: MSGBLDSVC net start | find / i "Site Server Message Builder Service"> NUL IF ErrorLevel == 1 goto stopiis set msgbldsvc = 1: stopiis net stop iisadmin /y>%%SystemRoot%/Restart.log if ErrorLevel == 1 goto stoperror goto stopped: stoperror rad ********* ********** Rem * Put any desired error-handling commands here. Rem * for example, if you have the Nt Resource Kit, Rem * You Could Use the following command to stop Rem * iis down the hard Way: Rem * kill.exe inetinfo.exe rem ****************** SET IISERR = 1: stopped remote *********** ******** REM * Put any desired commands to run while IIS is stopped here. REM * For example, if you have the Windows NT Resource Kit, REM * you could use the following command to pause REM * the restart For One Minute: Rem * Sleep.exe 60 Rem *******************: Startiis echo ---------------- ---- >>% SystemRoot% / Restart.log echo sta RT Date / Time: >>% systemroot% / restart.log echo. | Date | Find / I "current" >>% systemroot% / restart.log echo. | Time | Find / i "current" >>% systemroot% /Restart.log echo. >>% systemroot% / restart.log echo starting web services ... echo. if% w3svc% == 0 goto no3SVC Net Start W3SVC >>% SystemRoot% / Restart.log if Errorlevel == 1 set IISERROR = 1: NOW3SVC if% MSFTPSVC% == 0 goto NOMSFTPSVC net start MSFTPSVC >>% SystemRoot% / restart.log if errorlevel == 1 set IISERROR = 1: NOMSFTPSVC if% NNTPSVC% == 0 goto NONNTPSVC net start NNTPSVC >>% systemroot% / restart.log if errorlevel ==
1 set iiserror = 1: NonNTPSVC IF% SMTPSVC% == 0 goto Nosmtpsvc Net Start SMTPSVC >>% SystemRoot% / Restart.log if ErrorLevel == 1 set iiserror = 1: Nosmtpsvc IF% Broksvc% == 0 goto Nobroksvc Net Start Broksvc >>% systemroot% / restart.log if error = 1: Nobroksvc if% ldapsvc% == 0 GOTO NOLDAPSVC NET Start LDAPSVC >>% SystemRoot% / Restart.log if ErrorLevel == 1 set iiserror = 1: NoldapsVC IF% ldapsvc% == 0 goto Nomsgbldsvc net start msgbldsvc >>% systemroot% / restart.log if Errorlevel == 1 set iiserror = 1: Nomsgbldsvc if% iiserror% == 0 goto EXIT: Error Echo Restart Error. .. >>% systemroot% / restart.log echo one or more of the service. >>% systemroot% / restart.log echo please check the event. >>% systemroot% / restart .log rem ******************* Rem * Put any desired error-handling commands here. Rem * for example, if you have the windows nt resource kit, remote * You Could Use The Following Command To Rest Reth * The Server in Two Minutes: Rem * Shutdown.exe / L / R / T: 120 / y Rem ******************************: EXIT SET MSFTPSVC = set nntpsvc = set SMTPSVC = SET W3SVC = Set Broksvc = set LDAPSVC = set msgbldsvc = set iiserror = the information in this article applies to:
Microsoft Internet Information Server 1.0 Microsoft Internet Information Server 2.0 Microsoft Internet Information Server 3.0 Microsoft Internet Information Server 4.0
Last Reviewed: 3/30/2004 (4.0) Keywords: Kbhowto KB194916