【发布时间】:2016-11-09 10:06:58
【问题描述】:
我想编写一个脚本来在 IIS 服务器停止时自动启动它。
【问题讨论】:
标签: iis monitoring
我想编写一个脚本来在 IIS 服务器停止时自动启动它。
【问题讨论】:
标签: iis monitoring
您可以使用 IIS 管理脚本来查询服务器,然后在需要时启动它。
脚本位于%systemroot%\system32。
要查询您的服务器,只需从命令行运行 IIsWeb.vbs /query w3svc/1。
如果它没有运行,那么你可以运行IIsWeb.vbs /start w3svc/1 来启动它。
这里是article,其中包含有关这些脚本的更多信息。
【讨论】:
IIsWeb.vbs 在 Windows 10 专业版上不存在。
C:\Inetpub\AdminScripts 提供的脚本(假设默认安装位置),有startsrv.vbs、startweb.vbs - 两者都做得很好【讨论】:
如果您担心 ii 在失败后无法重新启动,您可以做的一件简单的事情是设置服务响应。如果您进入服务,然后查看 iis 的属性,您将看到一个恢复选项卡。更改每个失败选项以重新启动服务。您还可以做的一件事是创建一个批处理文件,其中包括 iis重置 并设置选项以运行程序并将其作为您选择的程序。
【讨论】:
例子:
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
【讨论】: