Monitoring the State of Application Pools

IIS 6.0

When IIS 6.0 is running in worker process application mode, you might want to monitor the state of the IIS application pools.

IIS 5.1 and earlier: The IIS WMI provider, and Application pools are not available, and therefore this topic does not apply.

This example code shows you how to use the JScript programming language to use the WMI ExecNotificationQuery method to query the application pools every three minutes and report any errors.

var service = GetObject( "winmgmts:/root/MicrosoftIISv2" ); 
var eventSource = service.ExecNotificationQuery( "SELECT * FROM __InstanceModificationEvent WITHIN 3 WHERE TargetInstance ISA 'IIsApplicationPoolSetting' AND TargetInstance.AppPoolState <> PreviousInstance.AppPoolState" ); 

while( true ) 
var newEvent = eventSource.NextEvent(); 

WScript.Echo( "==========================================" ); 
WScript.Echo( "New Event Message: " ); 
WScript.Echo( "Instance: " +  newEvent.TargetInstance.Name ); 
WScript.Echo( "Previous State: " +  newEvent.PreviousInstance.AppPoolState ); 
WScript.Echo( "New State: " +  newEvent.TargetInstance.AppPoolState );