Restarting Web Services and Scheduled Tasks with a Batch File

转载 2004年06月29日 22:57:00

Restarting Web Services and Scheduled Tasks with a Batch File

适用于
This article was previously published under Q194916

SUMMARY

This article describes how to shut down the Internet Information Server (IIS) services while other scheduled tasks are running.

MORE INFORMATION

The following instructions and batch file allow you to schedule IIS to restart on a daily basis at 1:00A.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.

  1. Log on to the Windows NT computer as an administrator.
  2. Make sure that the Task Scheduler service is set to automatically run by performing the following steps:

    1. Click the Start button, point to Settings, click Control Panel, and then double-click Services.
    2. Scroll to "Task Scheduler."
    3. If the status does not say running, then click the Start button.
    4. Click the Startup button.
    5. Make sure the Startup Type is set to Automatic, and then click OK.
    6. Click Close to exit the Services dialog box.
  3. Open a command prompt session and type the following command:

    at 1:00am /every:M,T,W,Th,F,S,Su "restart.bat"

  4. 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 LDAPSVC=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 BROKSVC set W3SVC=1 :BROKSVC net start | find /i "Site Server Authentication 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 REM ******************** 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 IISERROR=1 :STOPPED REM ******************** 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 Start 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 NOW3SVC 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 errorlevel==1 set IISERROR=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 services could not be restarted.>>%SystemRoot%/restart.log echo Please check the Event Viewer logs for more information.>>%SystemRoot%/restart.log REM ******************** REM * Put any desired error-handling commands here. REM * For example, if you have the Windows NT Resource Kit, REM * you could use the following command to restart REM * 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

第一个 Gradle 脚本及简单命令

第一个 Gradle 脚本及简单命令task helloworld { doLast { print 'Hello world!' } } /* ...
  • u012885276
  • u012885276
  • 2017年03月10日 17:14
  • 2011

面试流程中90%以上几率被问到的问题---务必要提前想好你的答案

ell me about yourself. 介绍自己。 What are your strengths? 你有哪些强项? What are your weaknesses? ?你有哪些弱点...
  • wuxiaobingandbob
  • wuxiaobingandbob
  • 2016年09月26日 12:55
  • 1607

Android实战技巧之十一:Android Studio和Gradle

经过两个多月的AS体验,我认为是时候将Android的开发环境迁移到AS上了。目前最新版本是1.0.2,除了UI控件拖拽偶尔崩溃的问题(Ubuntu),其他功能用来还是十分流畅和高效。打动我的有如下几...
  • lincyang
  • lincyang
  • 2015年02月17日 13:07
  • 88218

REST web services with Python, MongoDB, and Spatial data in the Cloud - Part 2

REST web services with Python, MongoDB, and Spatial data in the Cloud - Part 2 Tuesday, August 14, ...
  • alaclp
  • alaclp
  • 2012年09月04日 02:13
  • 1301

Android Task Killers: How do killing background tasks and services actually help?

http://kschang.hubpages.com/hub/Android-OS-Task-Killer-beneficial-or-placebo-only Android Tas...
  • choclover
  • choclover
  • 2012年01月23日 18:35
  • 884

Website Hosting and Migration with Amazon Web Services

  • 2017年05月10日 22:11
  • 12.44MB
  • 下载

Implementing a Distributed Two-Phase-Commit Scenario with Web Services and SAP NetWeaver PI 7.1.pdf

  • 2009年03月11日 10:11
  • 226KB
  • 下载

Developing Web Services with Apache CXF and Axis2, 3rd Edition Jan 2010.pdf

  • 2010年04月18日 22:07
  • 3.04MB
  • 下载

Building and Testing with Gradle笔记2——Gradle Tasks

声明一个Tasktask hello执行gradle tasks输出当前Project中所有task:tasks--------------------------------------------...
  • cwt8805
  • cwt8805
  • 2016年11月11日 14:02
  • 201

Web.Development.with.Go.Building.Scalable.Web.Apps.and.RESTful.Services

  • 2016年01月14日 17:22
  • 5.11MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Restarting Web Services and Scheduled Tasks with a Batch File
举报原因:
原因补充:

(最多只允许输入30个字)