Home > C# > Visual Studio, Attach debugger to w3wp process through macro

Visual Studio, Attach debugger to w3wp process through macro

October 12th, 2011 Leave a comment Go to comments

Here is a short macro that will attach the debugger to the first w3wp.exe process it can find in the process list. (Script assumes a w3wp.exe process is running. Expect error messages if it doesn’t ;))

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module Famvdploeg
    'Attach the debugger to a w3wp.exe process
    Sub AttachDebugger()
            'Get your hostname
            Dim hostname As String = System.Net.Dns.GetHostName
            'Load the debugger interface
            Dim debugger As EnvDTE80.Debugger2 = DTE.Debugger
            'Get a local transport, (this is the "Default")
            Dim trans As EnvDTE80.Transport = debugger.Transports.Item("Default")
            'Attach to the first w3wp.exe command which we find
            Dim dbgeng(3) As EnvDTE80.Engine
            dbgeng(0) = trans.Engines.Item("T-SQL")
            dbgeng(1) = trans.Engines.Item("T-SQL")
            dbgeng(2) = trans.Engines.Item("Managed")
            Dim process As EnvDTE80.Process2 = debugger.GetProcesses(trans, hostname).Item("w3wp.exe")
        Catch ex As System.Exception
        End Try
    End Sub
End Module
  1. No comments yet.
  1. No trackbacks yet.

Time limit is exhausted. Please reload CAPTCHA.