The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

path of exe file from window handle/process ID

I searched google and all related forums and only i can find is shortfilename('calc.exe' without complete path).
Is there any solution to this seemigly trivial (but obviously not) problem?
More precisely i'm trying to get list of active programs(those you can see by pressing alt-tab)

So is there some solution like:

function FilenameFromHandle(handle:integer):string
or something like that?
regular on BOS
Friday, July 25, 2008
Maybe it's as described in the help for the szExeFile field of the PROCESSENTRY32 structure at
Christopher Wells Send private email
Friday, July 25, 2008
Thanks a lot,i found solution based on what you said.
here is the function if somebody else needs it:

function GetProcessIDPath(ProcID: Cardinal): string;

  Snapshot: THandle;
  Module: TModuleEntry32;
  Snapshot := CreateToolhelp32Snapshot(th32cs_SnapModule, ProcID);
  if Snapshot <> THandle(-1) then try
    Module.dwSize := SizeOf(Module);
    if Module32First(Snapshot, Module) then begin
      Assert(ProcID = Module.th32ProcessID);
      Result := Module.szExePath;
    end else RaiseLastOSError;
  end else RaiseLastOSError;

//uses tlhelp32 library
regular on BOS
Friday, July 25, 2008
A simpler option is to use GetModuleFileNameEx with the hModule (second) parameter set to NULL. The limitation is that this function is not available on 95/98/ME (if you still care about those OSs)
Dan Shappir Send private email
Sunday, July 27, 2008

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz