How to: Attach to a Running Process
This topic applies to:
Visual Studio Edition |
Visual Basic |
C# |
C++ |
J# |
Web Dev |
Express Edition |
No |
No |
Yes |
No |
No |
Standard Edition |
Yes |
Yes |
Yes |
Yes |
Yes |
Pro/Team Edition |
Yes |
Yes |
Yes |
Yes |
Yes |
You can attach the Visual Studio debugger to any running process.
To attach to a running process
From the Debug menu, choose Attach to Process. (If no project is open, choose Attach to Process from the Tools menu.)
In the Attach to Process dialog box, find the program you want to attach to from the Available Processes list.
If the program you want to debug is running on another machine, you must first select the remote machine. (For more information, see How to: Select a Remote Machine.)
If the process is running under a different user account, check the Show processes from all users box.
If you are connected through Remote Desktop Connection, check the Show processes in all sessions box.
In the Attach to box, make sure that either the type of code you will debug is listed or that Automatic: Managed code appears. If it doesn't:
Click Select.
In the Select Code Type dialog box, click Debug these code types and select the types to debug.
Click OK.
Click the Attach button.
The Available Processes list is displayed automatically when you open the Processes dialog box. Processes can start and stop in the background while the dialog box is open, however, so the contents may not always be current. You can refresh the list at any time to see the current list of processes by pressing the Refresh button.
You can be attached to multiple programs when you are debugging, but only one program is active in the debugger at any given time. You can set the active program in the Debug Location toolbar. For more information, see How to: Set the Current Program.
All Debug menu execution commands affect the active program. You can break any debugged program from the Processes dialog box. For more information, see How to: Break Execution.
Note |
---|
For the debugger to attach to code written in Visual C++, the code needs to emit DebuggableAttribute. You can add this to your code automatically by linking with the /ASSEMBLYDEBUG linker option. |
Note |
---|
If you try to attach to a process owned by an untrusted user account, a security warning dialog confirmation will appear. For more information see Security Warning: Attaching to an Untrusted Process Can Be Dangerous. |
Note |
---|
In some cases, when debugging in a Terminal Services (Remote Desktop) session, the Available Processes list will not display all available processes. On Windows Server 2003 or later, if you are running Visual Studio as a limited user, the Available Processes list will not show processes running in Session 0, which is used for services and other server processes including w3wp.exe. You can solve the problem by running Visual Studio under an administrator account or by running Visual Studio from the server console rather than a Terminal Services session. If neither of those workarounds is possible, a third option is to attach to the process by running |
See Also
Tasks
How to: Attach to Managed Device Processes
Reference
Security Warning: Attaching to an Untrusted Process Can Be Dangerous