M 作 者: z_h_q_2000(★龙飞虎★) 2001-06-01 20:06:01 :0 :0
[回复] [打包] [转贴]
uses tlhelp32;
procedure TForm1.Button1Click(Sender: TObject);
var
pe:PROCESSENTRY32;
me:MODULEENTRY32;
hp,hm:Thandle;
b,b1:boolean;
begin
hp:=CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS,0);
pe.dwSize:=SizeOf(pe);
b:=Process32First(hp,pe);
while b do
begin
hm:=CreateToolHelp32SnapShot(TH32CS_SNAPModule,pe.th32ProcessID);
me.dwSize:=sizeof(ModuleEntry32);
if Module32First(hm,me) then
begin
b1:=Module32First(hm,me);
while b1 do
begin
if me.th32ModuleID=pe.th32ModuleID then
listbox1.Items.Add(me.szExePath);
b1:=Module32Next(hm,me);
end;
end;
b:=Process32Next(hp,pe);
end;
end;
而在NT系统中由于不支持toolhelp api,故
#include "psapi.hpp"
假使process id是 pid 的话:
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION
关键词:根据进程processid得到该进程的可执行文件名