Guest User

Untitled

a guest
Jun 19th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. Private Sub AttachToWorkerProcess(ByVal appName As String)
  2. Dim targetPid = FindPoolPIDByName(appName)
  3. If targetPid = -1 Then
  4. MessageBox.Show("Unable to find a worker process hosting " + appName)
  5. End If
  6.  
  7. Dim processes As EnvDTE.Processes = DTE.Debugger.LocalProcesses
  8.  
  9. For Each proc As EnvDTE.Process In processes
  10. If proc.ProcessID = targetPid Then
  11. proc.Attach()
  12. End If
  13. Next
  14.  
  15. End Sub
  16.  
  17. Private Function FindPoolPIDByName(ByVal appName As String) As Integer
  18. Dim sm As New Microsoft.Web.Administration.ServerManager()
  19.  
  20. Dim appPoolName As String = Nothing
  21. For Each site In sm.Sites
  22. For Each app In site.Applications
  23. If String.Equals(app.Path, "/" & appName, StringComparison.OrdinalIgnoreCase) Then
  24. appPoolName = app.ApplicationPoolName
  25. End If
  26. Next
  27. Next
  28.  
  29. If appPoolName Is Nothing Then
  30. MessageBox.Show("Unable to find application " & appName)
  31. End If
  32.  
  33. For Each wp In sm.WorkerProcesses
  34. If wp.AppPoolName = appPoolName Then
  35. Return wp.ProcessId
  36. End If
  37. Next
  38. Return -1
  39. End Function
  40.  
  41. Sub AttachToMyApp()
  42. AttachToWorkerProcess("MyApp")
  43. End Sub
Add Comment
Please, Sign In to add comment