Posted By

HologramX on 10/28/09


Tagged

web visualStudio vs2008


Versions (?)

Attach to w3wp.exe keyboard shortcut macro for Visual Studio


 / Published in: Visual Basic
 

Tools > Macro IDE > Add new item to MyMacros > Select Module, Name 'AttachToWebServer' > Copy/paste code.

To set as a keyboard shortcut go to Tools > Options > Keyboard, and search for the name of the macro (AttachToWebServer) and then assign a keyboard shortcut.

  1. Imports System
  2. Imports EnvDTE80
  3. Imports System.Diagnostics
  4.  
  5. Public Module AttachToWebServer
  6.  
  7. Public Sub AttachToWebServer()
  8.  
  9. Dim AspNetWp As String = "aspnet_wp.exe"
  10. Dim W3WP As String = "w3wp.exe"
  11.  
  12. If Not (AttachToProcess(AspNetWp)) Then
  13. If Not AttachToProcess(W3WP) Then
  14. System.Windows.Forms.MessageBox.Show(String.Format("Process {0} or {1} Cannot Be Found", AspNetWp, W3WP), "Attach To Web Server Macro")
  15. End If
  16. End If
  17.  
  18. End Sub
  19.  
  20. Public Function AttachToProcess(ByVal ProcessName As String) As Boolean
  21.  
  22. Dim Processes As EnvDTE.Processes = DTE.Debugger.LocalProcesses
  23. Dim Process As EnvDTE.Process
  24. Dim ProcessFound As Boolean = False
  25.  
  26. For Each Process In Processes
  27. If (Process.Name.Substring(Process.Name.LastIndexOf("\") + 1) = ProcessName) Then
  28. Process.Attach()
  29. ProcessFound = True
  30. End If
  31. Next
  32.  
  33. AttachToProcess = ProcessFound
  34.  
  35. End Function
  36.  
  37. End Module

Report this snippet  

You need to login to post a comment.