Quickly Attaching a Debugger to the Right Instance of w3wp.exe

On certain machines, I'm repeatedly using remote desktop to access a Windows 2003 server so that I can debug something running in the context of ASP.NET (web app, web service, etc). Since various apps and services on these machines are segregated in different app pools, the first thing I have to do when I run something like VS.NET and bring up the attach-to-process dialog is figure out which running instance of w3wp.exe is the one I need to attach to. Sometimes I get lucky and pick the right instance on the first try. Other times I miss and have to try the others one at a time. While this isn't something that takes a tremendous amount of time, the repetitive nature of this drives me nuts.
So I finally sat down and wrote a little script to automate this annoying procedure for me. The result is a javascript file that I can just run with the name of the app pool I'm interested in debugging on the command line, like so:
c:\>apdebug AcmeAppPool
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
Active app pools...
  AcmeAppPool (2860)
  MSSharePointAppPool (3268)
  DefaultAppPool (3652)
Launching debugger for 'AcmeAppPool' (2860)...
The script enumerates the running instances of w3wp.exe, displaying the app pool they host and their corresponding process ID, then launches the JIT debugging dialog if the app pool specified on the command line was active. Since I'm very often interested in the same app pool on a given machine, a desktop shortcut to that script with the right app pool name on the command line gets me to the right spot with just a double click.
A more detailed description, with sample output and a screenshot, along with links to the script source you can view and/or download for your own use can be found here.

Posted Aug 16 2006, 11:37 AM by mike-woodring

Comments

Craig wrote re: Quickly Attaching a Debugger to the Right Instance of w3wp.exe
on 08-16-2006 9:28 AM
What, you don't install Process Explorer on all your servers? Makes it pretty easy to figure out manually. :)

Of course, automating (as you did) is usually the better answer.
Mike wrote re: Quickly Attaching a Debugger to the Right Instance of w3wp.exe
on 08-16-2006 1:02 PM
Yes, I pretty much do :-), but having to run Process Explorer _in addition to_ VS.NET right after I login is just one more task. Besides, trying to automate this sequence of events was way more fun. Believe it or not, I'd never bumped into the Enumerator() concept in javascript before this. So not only did I end up with a one-double-click way to launch VS.NET & attach it to the right process, but I learned something too. Bonus!
David Douglass wrote re: Quickly Attaching a Debugger to the Right Instance of w3wp.exe
on 08-16-2006 3:51 PM
Microsoft supplies a script to do this. See http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/b8721f32-696b-4439-9140-7061933afa4b.mspx .

Craig is right about process explorer. View the properties of a process, .NET tab, and look at the app domains associated with the process.
Mike wrote re: Quickly Attaching a Debugger to the Right Instance of w3wp.exe
on 08-16-2006 4:57 PM
The point wasn't to see which process is hosting which app pool. The point of the script is to automate launching a debugger and telling it to attach to the process hosting an app pool I'm interested in. Running Process Explorer or the iisapp script doesn't accomplish that. I'd still need to run vs.net, bring up the attach-to-process dialog, pick the right process, then say attach. *That's* what's automated by this script. Pass an app pool name to a script and have it do all the work of identifying the right PID then attaching vs.net or another debugger to it in one go.
Jason Haley wrote Interesting Finds: August 16, 2006
on 08-16-2006 8:52 PM
Scott wrote re: Quickly Attaching a Debugger to the Right Instance of w3wp.exe
on 08-20-2006 7:01 PM
It seems we were both doing some automation that day. Here is a PowerShell version: http://odetocode.com/Blogs/scott/archive/2006/08/16/5624.aspx
Mike wrote re: Quickly Attaching a Debugger to the Right Instance of w3wp.exe
on 08-21-2006 4:17 PM
I like it! The PS version is even more compact. Will have to use that version on PS-enabled machines.
cj wrote re: Quickly Attaching a Debugger to the Right Instance of w3wp.exe
on 11-09-2006 6:47 AM
does this work on a remote IIS server?
Julien Couvreur wrote re: Quickly Attaching a Debugger to the Right Instance of w3wp.exe
on 08-23-2007 9:36 PM
Seems very useful. I'll try it next time.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?