VS, Visual Studio, , , w3wp.exe . , , . . , IE , Firefox. , IE , .
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module AttachToWebServer
Public Sub AttachToWebServer()
Dim AspNetWp As String = "aspnet_wp.exe"
Dim W3WP As String = "w3wp.exe"
If Not (AttachToProcess(AspNetWp)) Then
If Not AttachToProcess(W3WP) Then
System.Windows.Forms.MessageBox.Show(String.Format("Process {0} or {1} Cannot Be Found", AspNetWp, W3WP), "Attach To Web Server Macro")
End If
End If
End Sub
Public Function AttachToProcess(ByVal ProcessName As String) As Boolean
Try
Dim ProcessFound As Boolean = False
Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
Dim dbgeng(10) As EnvDTE80.Engine
Dim indexer As Integer = 0
For Each myEngine As Engine In trans.Engines
'Possible values here could be "T-SQL","Native","Managed","Workflow" "Managed/Native", "Script"
If myEngine.Name.Equals("Managed") Then
dbgeng(indexer) = myEngine
indexer += 1
End If
Next
Dim processes As EnvDTE.Processes = dbg2.GetProcesses(trans, "localhost")
For Each Process As EnvDTE80.Process2 In processes
If Process.Name.Contains(ProcessName) Then
Process.Attach2(dbgeng)
ProcessFound = True
End If
Next
Return ProcessFound
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Function
End Module