public static List<String> getListOfManagedProcess(bool showDetails) { var managedProcesses = new List<String>(); int currentProcessId = Process.GetCurrentProcess().Id; var corPublish = new CorPublish(); foreach (CorPublishProcess corPublishProcess in corPublish.EnumProcesses()) if (currentProcessId != corPublishProcess.ProcessId) // don't include the current process if (showDetails) managedProcesses.Add("[" + corPublishProcess.ProcessId + "] [ver=" + CorDebugger.GetDebuggerVersionFromPid(corPublishProcess.ProcessId) + "] " + corPublishProcess.DisplayName); else managedProcesses.Add(corPublishProcess.DisplayName); return managedProcesses; }
private void RefreshProcesses() { listBoxProcesses.Items.Clear(); CorPublish cp = null; int curPid = Process.GetCurrentProcess().Id; try { int count = 0; cp = new CorPublish(); { foreach (CorPublishProcess cpp in cp.EnumProcesses()) { if (curPid != cpp.ProcessId) // let's hide our process { string version = CorDebugger.GetDebuggerVersionFromPid(cpp.ProcessId); string s = "[" + cpp.ProcessId + "] [ver=" + version + "] " + cpp.DisplayName; listBoxProcesses.Items.Add(new Item(cpp.ProcessId, s)); count++; } } } // using if (count == 0) { listBoxProcesses.Items.Add(new Item(0, "(No active processes)")); } } catch (Exception) { if (cp == null) { listBoxProcesses.Items.Add(new Item(0, "(Can't enumerate processes")); } } }
public static void ProcessEnumCmd(string arguments, O2Thread.FuncVoidT1<CorPublishProcess> handleManagedProcess) // extended with Lambda method { var cp = new CorPublish(); CommandBase.WriteOutput("Active processes on current machine:"); foreach (CorPublishProcess cpp in cp.EnumProcesses()) { if (Process.GetCurrentProcess().Id == cpp.ProcessId) // let's hide our process { continue; } // Try and get the list of AppDomains, but watch for the process terminating IEnumerable appDomainEnum; try { appDomainEnum = cpp.EnumAppDomains(); } catch (COMException e) { if ((uint) e.ErrorCode == 0x80131301) //CORDBG_E_PROCESS_TERMINATED { continue; // process was terminated, ignore it } throw; // let error propogate up } if (handleManagedProcess != null) handleManagedProcess(cpp); else { CommandBase.WriteOutput("(PID: " + cpp.ProcessId + ") " + cpp.DisplayName); foreach (CorPublishAppDomain cpad in appDomainEnum) CommandBase.WriteOutput("\t(ID: " + cpad.Id + ") " + cpad.Name); } } }