Solved

Get EXE name

Posted on 2000-03-21
6
210 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_
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now