Public Function AttachToProcess(ByVal ProcessName As String) As Boolean Dim success As Boolean success = True Try Dim debugger As EnvDTE80.Debugger2 = DTE.Debugger Dim transport As EnvDTE80.Transport = debugger.Transports.Item("Default") Dim name As String = System.Security.Principal.WindowsIdentity.GetCurrent().Name name = name.Substring(0, name.IndexOf("\")) Dim process As EnvDTE80.Process2 = debugger.GetProcesses(transport, name).Item(ProcessName) process.Attach() Catch ex As System.Exception success = False End Try Return success End Function
Sub AttachToW3WP() If Not AttachToProcess("w3wp.exe") Then System.Windows.Forms.MessageBox.Show("Cannot attach to process") End If End Sub
Public Module AttachToProcess Public Function AttachToProcess(ByVal ProcessName As String) As Boolean Dim success As Boolean success = True Try Dim debugger As EnvDTE80.Debugger2 = DTE.Debugger Dim transport As EnvDTE80.Transport = debugger.Transports.Item("Default") Dim name As String = System.Security.Principal.WindowsIdentity.GetCurrent().Name name = name.Substring(0, name.IndexOf("\")) Dim process As EnvDTE80.Process2 = debugger.GetProcesses(transport, name).Item(ProcessName) process.Attach() Catch ex As System.Exception success = False End Try Return success End Function Sub AttachToW3WP() If Not AttachToProcess("w3wp.exe") Then System.Windows.Forms.MessageBox.Show("Cannot attach to process") End If End Sub End Module
Source: https://habr.com/ru/post/131937/
All Articles