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);
        }
예제 #2
0
        /// <summary>
        /// Attempts to retrieve the path to the binary from a running process
        /// Returns null on failure
        /// </summary>
        /// <param name="processId">The process to get the binary for</param>
        /// <returns>The path to the primary executable or null if it could not be determined</returns>
        private static string GetBinaryPathFromPid(int processId)
        {
            string programBinary = null;

            try
            {
                CorPublish        cp  = new CorPublish();
                CorPublishProcess cpp = cp.GetProcess(processId);
                programBinary = cpp.DisplayName;
            }
            catch
            {
                // try an alternate method
                using (ProcessSafeHandle ph = NativeMethods.OpenProcess(
                           (int)(NativeMethods.ProcessAccessOptions.ProcessVMRead |
                                 NativeMethods.ProcessAccessOptions.ProcessQueryInformation |
                                 NativeMethods.ProcessAccessOptions.ProcessDupHandle |
                                 NativeMethods.ProcessAccessOptions.Synchronize),
                           false,                        // inherit handle
                           processId))
                {
                    if (!ph.IsInvalid)
                    {
                        StringBuilder sb         = new StringBuilder(NativeMethods.MAX_PATH);
                        int           neededSize = sb.Capacity;
                        NativeMethods.QueryFullProcessImageName(ph, 0, sb, ref neededSize);
                        programBinary = sb.ToString();
                    }
                }
            }

            return(programBinary);
        }
예제 #3
0
        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);
                    }
                }
            }
        }
        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"));
                }
            }
        }