【问题标题】:Script to check IIS running or not用于检查 IIS 是否运行的脚本
【发布时间】:2016-11-09 10:06:58
【问题描述】:

我想编写一个脚本来在 IIS 服务器停止时自动启动它。

【问题讨论】:

    标签: iis monitoring


    【解决方案1】:

    您可以使用 IIS 管理脚本来查询服务器,然后在需要时启动它。

    脚本位于%systemroot%\system32

    要查询您的服务器,只需从命令行运行 IIsWeb.vbs /query w3svc/1

    如果它没有运行,那么你可以运行IIsWeb.vbs /start w3svc/1 来启动它。

    这里是article,其中包含有关这些脚本的更多信息。

    【讨论】:

    • IIsWeb.vbs 在 Windows 10 专业版上不存在。
    【解决方案2】:
    • 您可以在进程列表中查找 w3wp.exe(如果是 IIS6)
    • 您可以随时尝试“iisreset /start” - 我相信,即使 IIS 已经启动,它也可以工作
    • 看看微软在C:\Inetpub\AdminScripts 提供的脚本(假设默认安装位置),有startsrv.vbs、startweb.vbs - 两者都做得很好

    【讨论】:

    • 仅当服务当前处于活动状态时,不检查它是否正在运行
    【解决方案3】:

    如果您担心 ii 在失败后无法重新启动,您可以做的一件简单的事情是设置服务响应。如果您进入服务,然后查看 iis 的属性,您将看到一个恢复选项卡。更改每个失败选项以重新启动服务。您还可以做的一件事是创建一个批处理文件,其中包括 iis重置 并设置选项以运行程序并将其作为您选择的程序。

    【讨论】:

      【解决方案4】:

      在这里找到一些代码:https://social.msdn.microsoft.com/Forums/en-US/5a01d88b-2b7c-4d0b-bce0-9b90a236b64a/how-to-check-if-iis-is-running?forum=asmxandxml

      例子:

      Dim sc As New System.ServiceProcess.ServiceController("World Wide Web Publishing Service")
      
      If sc.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Stopped) Or sc.Status.Equals(System.ServiceProcess.ServiceControllerStatus.StopPending) Then
         ' Start the service if the current status is stopped.
         sc.Start()
      Else
         ' Stop the service if its status is not set to "Stopped".
         sc.Stop()
      End If
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-08-21
        • 1970-01-01
        • 1970-01-01
        • 2019-03-10
        • 2010-10-21
        • 1970-01-01
        相关资源
        最近更新 更多