Created
May 11, 2011 13:47
-
-
Save hugoware/966466 to your computer and use it in GitHub Desktop.
Attach To Process Visual Studio Macros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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