Click here to Skip to main content
13,353,462 members (65,736 online)
Click here to Skip to main content
Add your own
alternative version


4 bookmarked
Posted 14 Dec 2012

Macro to attach debugger to correct w3wp process.

, 16 Feb 2013
Rate this:
Please Sign up or sign in to vote.
Macro to attach visual studio debugger to w3wp apppool hosting your webservice.


The below macro can be used to attach Visual Studio debugger with the correct w3wp process to debug web application.


While working on webservices we often need to debug server side code using visual stuido and to do that we need to attach the corresponding apppool which is hosting our webservice.

This can be achieved using Visual Studio Attach to Process window where we can select the correct w3wp process to debug the code.

Most of the time developers select all w3wp process available in Attach to Process window. As the information about the apppool hosting the webservice is missing in the Attach to Process window.

With this macro we can attache debugger to the correct w3wp apppool which is hosting our webservice.

Also by creating macro icon in Visual Studio toolbar, bebugger can be attach with a single click.

Below is the link which would help you in the creation of the macro and creating a shortcut for it in visual studio.

Using the code

In MacroID add the below code in your Module. Replace your apppool name in the below code as shown below.

If (input.ToString().Contains("<nameOfapppool>")) Then.

To know the apppoolname in which your application is running run the below command in command prompt after going to directory C:\Windows\System32\inetsrv\

appcmd.exe list wp

the name of your apppool will appear like as shown in the below image.


Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics

Public Module Module1
    Public Sub AttachW3WP()
        Const lngCancelled_c As Long = 0
        Dim strCmd As String
        strCmd = "C:\Windows\System32\inetsrv\appcmd.exe list wp"
        If Len(strCmd) = lngCancelled_c Then
            Exit Sub
        End If
    End Sub

    Public Function CommandLine(ByVal command As String) _
    As Boolean
        On Error GoTo Err_Hnd
        Dim WshShell, oExec, input
        WshShell = CreateObject("WScript.Shell")
        oExec = WshShell.Exec(command)
        input = ""
        Dim flag = True
        Do While flag
            If Not oExec.StdOut.AtEndOfStream Then
                input = oExec.StdOut.ReadLine
                If (input.ToString().Contains("<nameOfapppool>")) Then
                    Dim attached As Boolean = False
                    Dim proc As EnvDTE.Process
                    Dim procID As String
                    Dim tempString As String
                    procID = input.ToString().Split("(")(0).Split(" ")(1).Replace("""", "")
                    For Each proc In DTE.Debugger.LocalProcesses
                        If (proc.ProcessID = procID) Then
                            attached = True
                            flag = False
                            Exit For
                        End If
                End If
                flag = False
            End If
        CommandLine = True
        Exit Function
        CommandLine = False
    End Function
End Module

Points of Interest

I found macros to be very helpful and I always try to use them to save time.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Technical Lead
India India
Nitin Garg,
Working in MNC as a Technical Lead.
Worked on .net 4.0, Silverlight, WCF RIA Services and Entity Framework.
Currently working on Biztalk server.

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 17 Feb 2013
Article Copyright 2012 by Nitin_Garg
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid