?
Solved

Get EXE name

Posted on 2000-03-21
6
Medium Priority
?
219 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
Industry Leaders: 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 200 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

771 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