Win32: How to enumerate child processes?

后端 未结 1 1592
说谎
说谎 2020-12-17 03:21

What\'s the best way to enumerate the child processes of the currently running process under Win32? I can think of a couple of ways to do it, but they seem overly complicate

1条回答
  •  天命终不由人
    2020-12-17 04:16

    You could use the toolhelp API

    #include 
    
    Process32First() 
    

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

    0 讨论(0)
提交回复
热议问题