开发者

Win32: How to enumerate child processes?

开发者 https://www.devze.com 2022-12-16 19:28 出处:网络
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 complicated and slow. Here\'s the req

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 complicated and slow. Here's the requirements for the solution:

  1. Specifically I need to know if any there are any processes currentl开发者_如何学Goy running which were started by the current process.
  2. Will be running on WinXP and should not require distributing special DLL's.
  3. Should not require a lot of CPU overhead (it will be running periodically in the background).
  4. I'll eventually be writing this in Delphi, but I can convert from whatever language you have the code in. Mostly I'm looking for the most efficient set of Win32 API's to use.

Thanks!


You could use the toolhelp API

#include <tlhelp32.h>

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

精彩评论

暂无评论...
验证码 换一张
取 消