Win32:如何枚举子进程? [英] Win32: How to enumerate child processes?
本文介绍了Win32:如何枚举子进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Win32下枚举当前正在运行的进程的子进程的最佳方法是什么?我可以想到几种方法来做到这一点,但它们似乎过于复杂和缓慢.以下是解决方案的要求:
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:
- 具体来说,我需要知道是否有任何当前正在运行的进程是由当前进程启动的.
- 将在 WinXP 上运行,不需要分发特殊的 DLL.
- 不应需要大量 CPU 开销(它将在后台定期运行).
- 我最终会在 Delphi 中编写此代码,但我可以从您拥有代码的任何语言进行转换.主要是我在寻找最高效的 Win32 API 集以供使用.
谢谢!
推荐答案
你可以使用 toolhelp API
You could use the toolhelp API
#include <tlhelp32.h>
Process32First()
循环使用
Process32Next()
http://www.codeproject.com/KB/threads/processes.aspx
编辑德尔福
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;
这篇关于Win32:如何枚举子进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文