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;
}