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
Solved

Get EXE name

Posted on 2000-03-21
6
216 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
Using idhttp to login to instagram 2 106
Downloading email attachments 2 79
Tviruailstringtree sort multi columns on header click 1 74
Multi-layered image in FireMonkey 9 49
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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