Win32: How to list child processes?

What is the best way to list the child processes of the current process under Win32? I can come up with a couple of ways to do this, but they seem too complicated and slow. Here are the solution requirements:

  • In particular, I need to know if there are any processes in it that were started by the current process.
  • It will run on WinXP and should not require the distribution of special DLLs.
  • It does not require a lot of processor overhead (it will periodically run in the background).
  • In the end, I will write this in Delphi, but I can convert from any language in which you have the code. I am mainly looking for the most efficient Win32 API set to use.

Thank!

+3
source share
1 answer

You can use the dashboard API

#include <tlhelp32.h>

Process32First() 

And a loop using

Process32Next()

http://www.codeproject.com/KB/threads/processes.aspx

Edit delphi

uses tlhelp32;

procedure FillAppList(Applist: Tstrings); 
var   Snap:THandle; 
        ProcessE:TProcessEntry32; 
begin 
     Applist.Clear; 
     Snap:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 
     ProcessE.dwSize:=SizeOf(ProcessE); 
     if Process32First(Snap,ProcessE) then 
     begin 
          Applist.Add(string(ProcessE.szExeFile)); 
          while Process32Next(Snap,ProcessE) do 
                 .. compare parent id
      end 
      CloseHandle(Snap); 
end;
+2
source

Source: https://habr.com/ru/post/1729195/


All Articles