Archive

Posts Tagged ‘attach debugger’

Visual Studio, Attach debugger to w3wp process through macro

October 12th, 2011 No 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()
        Try
            '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")
            process.Attach2(dbgeng)
        Catch ex As System.Exception
            MsgBox(ex.Message)
        End Try
 
    End Sub
End Module