Compartir a través de


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

  1. From the Debug menu, choose Attach to Process. (If no project is open, choose Attach to Process from the Tools menu.)

  2. In the Attach to Process dialog box, find the program you want to attach to from the Available Processes list.

    1. 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.)

    2. If the process is running under a different user account, check the Show processes from all users box.

    3. If you are connected through Remote Desktop Connection, check the Show processes in all sessions box.

  3. 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:

    1. Click Select.

    2. In the Select Code Type dialog box, click Debug these code types and select the types to debug.

    3. Click OK.

  4. 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.

NoteNote

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.

NoteNote

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.

NoteNote

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 vsjitdebugger.exe -pProcessId from the Windows command line. You can determine the process id using tlist.exe. To obtain tlist.exe, download and install Debugging Tools for Windows, available at https://www.microsoft.com/whdc/devtools/debugging/default.mspx.

See Also

Tasks

How to: Attach to Managed Device Processes

Reference

Security Warning: Attaching to an Untrusted Process Can Be Dangerous

Concepts

Debugger Security

Other Resources

Attaching to Running Processes