我已经找到答案了,用下面的函数(David Jiang写的,我改了一点点)
function GetExeFileName(wh:Thandle):string;
var
pword;
thh:Thandle;
lppe:tagProcessentry32;
begin
Result:='';
GetWindowThreadProcessId(wh,@p);
thh:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
lppe.dwSize:=sizeof(lppe);
Process32First(thh,lppe);
if lppe.th32ProcessID=p then
begin
result:=lppe.szExeFile;
exit;
end;
while Process32Next(thh,lppe) do
if lppe.th32ProcessID=p then
begin
result:=lppe.szExeFile;
break;
end;
end;