Enumprocs...

delphi package - easy access to kernel objects etc.
Post Reply
Jeff_Lawton
Posts: 7
Joined: Tue Jul 20, 2004 8:20 pm
Location: Sacramento, CA
Contact:

Enumprocs...

Post by Jeff_Lawton »

I have a couple of questions..

I use the following code to step through all the top level processes running on the system..

Code: Select all

procedure BuildProcessList(tsl : TStringList);
var
  i1 : integer;
  pl : TDAProcess;
  WinEXE  : String;
  WinHwnd : Cardinal;
  ProcessHandle : IProcess;
begin
  pl := EnumProcesses;
  for i1 := 0 to high(pl) do
  begin
    try
      WinEXE := ExtractFilename(pl[i1].exeFile);
      WinHwnd := Process(pl[i1].exeFile).GetHandle(PROCESS_ALL_ACCESS).Handle;
      ProcessHandle := MadKernel.Window(WinHwnd).OwnerProcess;
      //CODE HERE TO TO DO STUFF
    except
      continue;
    end;
  end;
end;
Now I was wondering if there was a way to use IProcess or something to be able to find all the children that belong to the top level process. I have gone through the docs several times, but didn't really find any reference.

I know I can use enumprocs to go through all the open windows, and then I am able to link the windows upto the EXE for my own tracking purposes, but I would like a way I could find or open a top level window, and be able to find all the sub windows that opened, and are owned by the main window.

Any suggestions would be great.

Regards,

Jeff Lawton
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Enumprocs...

Post by madshi »

Hi Jeff,

you're making your life harder than necessary. You're using both my old enumStuff and the new madKernel stuff. If you want to avoid using madKernel, you can use the old enumStuff, which is free and comes with sources. But if you use madKernel, anyway, there's no reason to use enumStuff anymore.

Code: Select all

  with Processes do
    for i1 := 0 to ItemCount - 1 do
      with Items[i1].Windows_ do
        for i2 := 0 to ItemCount - 1 do
          ShowMessage(Items[i2].ClassName);
This loops through all processes and for each process it loop through all top level windows. Is that what you need?

Code: Select all

      WinEXE := ExtractFilename(pl[i1].exeFile);
      WinHwnd := Process(pl[i1].exeFile).GetHandle(PROCESS_ALL_ACCESS).Handle;
You can do that. But "Process(exeFileString)" internally enumerates all processes again and compares each process name to the exeFileString you specified. It's much better (faster) to directly use madKernel for everything.

Besides, "IProcess.GetHandle(...).Handle" returns a *process* handle, not a window handle - which are 2 totally different beasts!
Post Reply