win9x下据说下面的可以,没试过:
procedure TForm1.Button2Click(Sender: TObject);
var
fname: array[0..MAX_PATH]of char;
wnd : integer;
Instance: LongWord;
begin
wnd := FindWindow('IEFrame',nil);
if wnd = 0 then ShowMessage('not find');
Instance := GetWindowLong(Wnd, GWL_HINSTANCE);
GetModuleFileName(Instance,fname,MAX_PATH);
caption := fname;
end;
win2k下:
procedure TForm1.Button2Click(Sender: TObject);
type
integer = DWORD; // different versions of psapi.pas floating around
var
i,j,pidNeeded,modNeeded : Integer;
PIDList : array[0..1000] of Integer; // 1000 should be enough
MODList : array[0..1000] of HInst;
PIDName : array [0..MAX_PATH - 1] of char;
MODName : array [0..MAX_PATH - 1] of char;
PH : THandle;
wnd: integer;
pID: integer;
begin
wnd := FindWindow('IEFrame',nil);
GetWindowThreadProcessId(wnd,@pID);
if not enumprocesses (@PIDList, 1000, pidNeeded) then
begin
ShowMessage('Need psapi.dll');
exit;
end;
for i := 0 to (pidNeeded div sizeof (Integer)- 1) do
begin
PH := OpenProcess (PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False,PIDList);
if PH <> 0 then
begin
if GetModuleBaseName (PH, 0, PIDName, sizeof (PIDName)) > 0 then
begin
ListBox1.Items.Add('process : ' + PIDName);
if not EnumProcessModules (PH,@MODList,1000, modNeeded) then modNeeded:= 0;
if pID = PIDList then
begin
//caption := PIDName; //here, get the name
if GetModuleFileNameEx (PH, MODList[0], MODName,sizeof(MODName)) > 0 then
caption := MODName;
end;
if PH > 0 then CloseHandle(PH);
end;
end;
end;
end;