Solved

Get EXE name

Posted on 2000-03-21
6
217 Views
Last Modified: 2010-04-04
If I know the handle to a window, how can I get the app filename?
0
Comment
Question by:bogieman_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Expert Comment

by:ckaneta
ID: 2640754
ExtractFileName(Application.EXEname)
will return the exename(full path, I think) of your program
if you need exename of any program, well
not sure on that one
0
 
LVL 1

Author Comment

by:bogieman_
ID: 2640788
This question has a deletion request Pending
0
 
LVL 2

Expert Comment

by:craig_capel
ID: 2640794
I noticed you have two questions up of the same question.... if i give you this code, the other 50 points will have to go to Barry, He answered my question which whas this very one.....

And you Answer is....


function GetWindowExeName(Handle: THandle): String;
 var
PE: TProcessEntry32;
 Snap: THandle;
ProcessId: cardinal;
begin
 GetWindowThreadProcessId(Handle,@ProcessId);
 Snap:= CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if Snap <> 0 then begin
 if Process32First(Snap, PE) then
  if PE.th32ProcessID = ProcessId then
  Result:= String(PE.szExeFile)
   else while Process32Next(Snap, PE) do
 if PE.th32ProcessID = ProcessId then begin
  Result:= String(PE.szExeFile);
   break;
    end;
    CloseHandle(Snap);
   end;
 end;

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:craig_capel
ID: 2640799
This question no longer is pending deletion
0
 
LVL 2

Expert Comment

by:craig_capel
ID: 2640800
Stop this Deletion Now!!!
0
 

Accepted Solution

by:
deeptesla earned 50 total points
ID: 2640825
function GetAppName(hwindow: HWND): string;
var
  h: HMODULE;
begin
  SetLength(Result, 100);
  h := GetClassLong(hwindow, GCL_HMODULE);
  GetModuleFileName(h, PChar(Result), 100);
end;

for filename:
ExtractFileName(GetAppName(theHandle))

for file path:
ExtractFilePath(GetAppName(theHandle))

will get the job done for you...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question