Find pid Visual Studio that debugs my process

I know that I can find out if a process is being debugged through a call to Debugger.IsAttached in .NET, but I would like to get the PID of Visual Studio, which is the debugging of processes. Is it possible?

+6
source share
2 answers

You can use the TryGetVSInstance method described in this answer to access each instance of the Visual Studio EnvDTE COM Automation object. Once you do this, just go to DTE.Debugger.DebuggedProcesses and check if any of them points to the same process identifier as the process concerned.

+2
source

This> worked for me.

 public static Process GetParent(Process process) { var processName = process.ProcessName; var nbrOfProcessWithThisName = Process.GetProcessesByName(processName).Length; for (var index = 0; index < nbrOfProcessWithThisName; index++) { var processIndexdName = index == 0 ? processName : processName + "#" + index; var processId = new PerformanceCounter("Process", "ID Process", processIndexdName); if ((int)processId.NextValue() == process.Id) { var parentId = new PerformanceCounter("Process", "Creating Process ID", processIndexdName); return Process.GetProcessById((int)parentId.NextValue()); } } return null; } 
0
source

Source: https://habr.com/ru/post/918742/


All Articles