views:

434

answers:

4

I want to attach to a process(a.exe) as soon as it is spawned, is it doable with VS? I only know the name of the process. Actually what I want to accomplish is set a breakpoint in c# code, but the code is belonging to another executable which will be launched by current running application(c.exe). The code is inside the initialize period so it is impossible for me to do the attach manually.

Thanks.

+6  A: 

When I've faced this situation before (and I controlled both processes), I found a decent workaround is to put a call to Debugger.Launch() in the spawning process' entry point. VS will then pop up a dialog box and let you attach to the process.

Mark Simpson
+1  A: 

How about this: open project for a.exe in VS, set the breakpoints etc. Then open Project Properties for a.exe, Debugging tab, and set Command to c.exe. Then just hit Debug.

Unfortunately I never did this with managed projects, so I can be off the mark here. However, that's how I would do it with unmanaged (C++) projects. I think managed debugger should support it too.

atzz
A: 

If C# code being launched by unmanaged code then make sure you check "Unmanaged code debugging" @Project properties --> debug options..

Regards Phani

Phanidhar
A: 

MSDN has How to: Launch the Debugger Automatically - this would allow one to skip the plethora of busywork clicking confirmation dialog boxes [without turning of UAC or other messing].

Ruben Bartelink