Skip to content

Instantly share code, notes, and snippets.

@hugoware
Created May 11, 2011 13:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugoware/966466 to your computer and use it in GitHub Desktop.
Save hugoware/966466 to your computer and use it in GitHub Desktop.
Attach To Process Visual Studio Macros
'requests a name and attaches to that process
Public Sub AttachToNamedProcess()
Dim process As String = InputBox("What process name", "Process Name", "w3wp.exe")
'make sure something was provided
If process Is Nothing Then process = ""
process = process.Trim()
If String.IsNullOrEmpty(process) Then Return
_AttachToProcess(process, False)
End Sub
'attaches to a web process
Public Sub AttachToWebProcess()
_AttachToProcess("w3wp.exe", True)
End Sub
'attaches to a process by file name (not full path)
Private Sub _AttachToProcess(ByVal process As String, ByVal ignoreCase As Boolean)
'clear existing
DTE.Debugger.DetachAll()
'determine how to check case
Dim compare As StringComparison = StringComparison.Ordinal
If ignoreCase Then compare = StringComparison.OrdinalIgnoreCase
'find processes with a matching name
For Each proc As EnvDTE.Process In DTE.Debugger.LocalProcesses
Dim file As String = Path.GetFileName(proc.Name)
If file.Equals(process, compare) Then
proc.Attach()
End If
Next
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment