Beispiel #1
0
        private void RefreshProcessList()
        {
            uint[]        processIds;
            IntPtr        snapshotHandle;
            MODULEENTRY32 moduleEntry32;
            ListViewItem  listViewItem;
            string        t;
            bool          isDotNetProcess;
            bool          is64;

            lvwProcesses.Items.Clear();
            processIds = NativeProcess.GetAllProcessIds();
            if (processIds is null)
            {
                return;
            }
            moduleEntry32 = MODULEENTRY32.Default;
            foreach (uint processId in processIds)
            {
                if (processId == 0)
                {
                    continue;
                }
                snapshotHandle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, processId);
                if (snapshotHandle == INVALID_HANDLE_VALUE)
                {
                    continue;
                }
                if (!Module32First(snapshotHandle, ref moduleEntry32))
                {
                    continue;
                }
                listViewItem = new ListViewItem(moduleEntry32.szModule);
                listViewItem.SubItems.Add(processId.ToString());
                listViewItem.SubItems.Add(moduleEntry32.szExePath);
                isDotNetProcess = false;
                while (Module32Next(snapshotHandle, ref moduleEntry32))
                {
                    if ((t = moduleEntry32.szModule.ToUpperInvariant()) == "MSCOREE.DLL" || t == "MSCORWKS.DLL" || t == "MSCORJIT.DLL" || t == "CLR.DLL" || t == "CLRJIT.DLL")
                    {
                        listViewItem.BackColor = Cache.DotNetColor;
                        isDotNetProcess        = true;
                        if (Cache.Is64BitProcess && Is64BitPE(moduleEntry32.szExePath, out is64) && !is64)
                        {
                            listViewItem.Text += _resources.GetString("Str32Bit");
                        }
                        break;
                    }
                }
                if (Cache.Is64BitProcess && !isDotNetProcess && Is64BitPE(listViewItem.SubItems[2].Text, out is64) && !is64)
                {
                    listViewItem.Text += _resources.GetString("Str32Bit");
                }
                if (!mnuOnlyDotNetProcess.Checked || isDotNetProcess)
                {
                    lvwProcesses.Items.Add(listViewItem);
                }
            }
            lvwProcesses.AutoResizeColumns(false);
        }
        public static List <ProcessInfo> GetRunningProcesses()
        {
            var processIds  = NativeProcess.GetAllProcessIds();
            var moduleEntry = MODULEENTRY32.Default;

            var result = new List <ProcessInfo>(processIds.Length);

            foreach (uint processId in processIds)
            {
                if (processId == 0)
                {
                    continue;
                }
                var snapshotHandle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, processId);
                if (snapshotHandle == INVALID_HANDLE_VALUE)
                {
                    continue;
                }
                if (!Module32First(snapshotHandle, ref moduleEntry))
                {
                    continue;
                }

                var process = new ProcessInfo()
                {
                    Id = processId
                };

                bool isDotNetProcess = false;

                process.Is64BitPE  = Is64BitPE(moduleEntry.szModule, out bool is64)? is64 : (bool?)null;
                process.ExePath    = moduleEntry.szExePath;
                process.ModuleName = moduleEntry.szModule;
                while (Module32Next(snapshotHandle, ref moduleEntry))
                {
                    string t = moduleEntry.szModule.ToUpperInvariant();
                    if (t == "MSCOREE.DLL" || t == "MSCORWKS.DLL" || t == "CLR.DLL" || t == "CORECLR.DLL")
                    {
                        isDotNetProcess = true;
                        break;
                    }
                }

                process.IsDotNetProcess = isDotNetProcess;
                result.Add(process);
            }

            return(result);
        }
Beispiel #3
0
    public IEnumerable <ProcessInfo> EnumerateProcesses()
    {
        var processIds = NativeProcess.GetAllProcessIds();

        if (processIds is null || processIds.Length == 0)
        {
            yield break;
        }
        foreach (uint processId in processIds)
        {
            if (processId == 0)
            {
                continue;
            }

            var processInfo = GetProcessInfo(processId);
            if (processInfo is not null)
            {
                yield return(processInfo);
            }
        }
    }