// apdump.js // // App Pool dump script for Windows 2003 Server. This little script enumerates // running instances of w3wp.exe on the local machine, and displays the process // ID of each along with the app pool it hosts. // // Mike Woodring // Bear Canyon Consulting LLC // http://www.bearcanyon.com // http://www.pluralsight.com/mike // // Enumerate the running instances of w3wp.exe. // var wmi = GetObject("winmgmts://./root/cimv2"); var w3wpInstances = wmi.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'w3wp.exe'"); if( w3wpInstances.Count == 0) { WScript.Echo("No running instances of w3wp.exe found."); WScript.Quit(); } // Setup a regular expression that can parse the -ap command line switch // for an instance of w3wp.exe. VBScript's regex support doesn't include // named capture, but it does support capturing groups which can be referred // to by index. // var regexp = /-ap\s+\"([^.]+)\"/i; // Iterate over the collection of w3wp.exe processes identified above, // using the regex to extract the contents of the -ap (app pool) // command line option. // var enumerator = new Enumerator(w3wpInstances); for( enumerator.moveFirst(); !enumerator.atEnd(); enumerator.moveNext() ) { var w3wp = enumerator.item(); var matches = regexp.exec(w3wp.CommandLine); if( matches.length == 2 ) { WScript.Echo(matches[1] + " (" + w3wp.ProcessId + ")"); } }