Thanks kretzschmar
In fact, I enumerate all the handle of the running application.
I have alle their handle.
But I wanna have their instance.
cause the api GetModuleFileName work only with the instance
Thanks
Main Topics
Browse All TopicsHi, everyone
I wanna find the instance of an exe.
But I only had is handle, I don't know what exe is and where it is
And What is the difference between a handle and an instance??
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
well, guessing you've a windowhandle
then look at the windows api GetWindowThreadProcessId
from the helpfile
The GetWindowThreadProcessId function retrieves the identifier of the thread that created the specified window and, optionally, the identifier of the process that created the window. This function supersedes the GetWindowTask function.
DWORD GetWindowThreadProcessId(
HWND hWnd, // handle of window
LPDWORD lpdwProcessId // address of variable for process identifier
);
Parameters
hWnd
Identifies the window.
lpdwProcessId
Points to a 32-bit value that receives the process identifier. If this parameter is not NULL, GetWindowThreadProcessId copies the identifier of the process to the 32-bit value; otherwise, it does not.
Return Values
The return value is the identifier of the thread that created the window.
--- end paste
in delphi it should work like
(not tested myself)
var
ProcessHandle : THandle;
begin
if YourHandle <> 0 then
GetWindowThreadProcessId(Y
//now work with the ProcessHandle
end;
hope this helps
meikl ;-)
thinks the solution is not too far from your post,
but it doesn't work.
Look try this code, you'll understand:
// NORMAL Method
procedure TMainForm.Button5Click(Sen
var p :array[0..255]of char;
begin
GetModuleFileName(hinstanc
messageboxa(handle, p, '', 0);
end;
// METHOD with GetWindowThreadProcessId
procedure TMainForm.Button6Click(Sen
var p :array[0..255]of char;
inst :thandle;
begin
GetWindowThreadProcessId(h
GetModuleFileName(inst,p, 255);
messageboxa(handle, p, '', 0);
end;
I try on the handle of my application.
GetWindowThreadProcessId didn't return me the instance
cause the result of GetWindowThreadProcessId and the veritable instance are not the same ??
so you want to get a windows executable ?
if so then use:
uses windows, psapi;
function IsWinNT4Plus: Boolean;
var VI: TOSVersionInfo;
begin
FillChar(VI, SizeOf(TOSVersionInfo), 0);
VI.dwOSVersionInfoSize:=Si
GetVersionEx(VI);
with VI do
Result:=(dwPlatformId = VER_PLATFORM_WIN32_NT)and(
end;
function GetWindowFileName(const hWin: HWND): string;
var lpBuff: PChar;
nCount: Integer;
dwProcessId: Cardinal;
hInst: Cardinal;
hProcess: Cardinal;
begin
Result:='';
nCount:=1024;
GetMem(lpBuff, nCount);
try
if IsNT4Plus then begin
hInst:=GetWindowLong(hWin,
GetWindowThreadProcessId(h
hProcess:=OpenProcess(PROC
if hProcess > 0 then
try
GetModuleFileNameEx(hProce
finally
CloseHandle(hProcess);
end;
end else begin
GetWindowModuleFileName(hW
end;
Result:=string(lpBuff);
finally
FreeMem(lpBuff);
end;
end;
//What is the difference between a handle and an instance??
an instance is a handle,
a instance is a module handle of the exe/dll
for example take your example and modify :
var
p :array[0..255]of char;
begin
showmessage(inttostr(hinst
GetModuleFileName(hinstanc
showmessage(inttostr(GetMo
so if you want to have the "instance" of an exe then call GetModuleHandle().
how are you getting the window handle of the exe to begin with? ie are you using enumwindows etc?
Business Accounts
Answer for Membership
by: kretzschmarPosted on 2002-05-15 at 07:47:33ID: 7011210
>I don't know what exe is
its a executable file, just a program like notepad,
just an application
>and where it is
normally on the filesystem, if no instance from it is started
>what is an instance
if you execute an executeable file, then you have an instance of this application started, if you execute the executeable file moreoften without finishing an instance, then you've started some instaces from the same executable file, like
if you start notepad.exe twice, then you've two instances of the notepad.exe running on your system.
>what is a handle
a handle is an id to a os-object, there may various handles
(windowhandle, processhandle,..)
well to go back to your question
>I wanna find the instance of an exe
tell us what kind of handle you have
meikl ;-)