Answers for "get child processes c#"

C#
0

get child processes c#

/// Not my code, but this does work. I used it in an anticheat engine.
public static List<Process> GetChildProcesses(this Process process)
            {
                var results = new List<Process>();
                string queryText = string.Format("select processid from win32_process where parentprocessid = {0}", process.Id);
                using (var searcher = new ManagementObjectSearcher(queryText))
                {
                    foreach (var obj in searcher.Get())
                    {
                        object data = obj.Properties["processid"].Value;
                        if (data != null)
                        {
                            var childId = Convert.ToInt32(data);
                            var childProcess = Process.GetProcessById(childId);
                            if (childProcess != null)
                                results.Add(childProcess);
                        }
                    }
                }
                return results;
            }
Posted by: Guest on March-15-2021

C# Answers by Framework

Browse Popular Code Answers by Language