您可以从启动任务运行以下脚本(确保创建提升的后台任务):
Timeout= 30000
set events = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecNotificationQuery("select * from __instancecreationevent where targetinstance isa 'Win32_NTLogEvent' and TargetInstance.LogFile='System' and TargetInstance.EventCode=5002")
Do
WScript.Echo "==========================================================================="
WScript.Echo "Listening for IIS Rapid Fail Protection Events"
Set objLatestEvent = events.NextEvent
Wscript.Echo objLatestEvent.TargetInstance.Message
' get the AppPool name from the Eventlog message
appPool = objLatestEvent.TargetInstance.InsertionStrings(0)
WScript.Echo "Restarting Application Pool '" & appPool & "' in " & Timeout & " milliseconds"
WScript.Sleep(Timeout)
'construct ADSI path to failed AppPool and start by setting AppPoolCommand to 1
set pool = GetObject("IIS://localhost/w3svc/AppPools/" & appPool)
pool.AppPoolCommand = 1
pool.SetInfo
WScript.Echo "AppPool " & appPool & " restarted"
WScript.Echo "==========================================================================="
WScript.Echo
Loop
使用 WMI 它将侦听 IIS RFP 事件。这是通过与 结合来完成ExecNotificationQuery
的NextEvent
。调用NextEvent
将阻塞,直到新事件到达。发生这种情况时,脚本会等待 30 秒并重新启动应用程序池。
无论如何,如果 RFP 启动,可能更适合了解您的流程为何一次又一次地崩溃。