如何由窗口 句柄得到 可执行文件的路径?(200分)

  • 主题发起人 主题发起人 13708782004
  • 开始时间 开始时间
1

13708782004

Unregistered / Unconfirmed
GUEST, unregistred user!
如何由窗口 句柄得到 可执行文件的路径?
 
GetModuleFileName(YourHandle,Path,256);
 
出200分的问题就这么简单,在帮帮我啊!
 
用FindWindow
 
function GetModuleFileNameEx(hProcess: Cardinal; hModule: Cardinal; lpFilename: pChar; nSize: LongInt): LongInt; stdcall; external 'psapi.dll' name 'GetModuleFileNameExA';<br><br>GetModuleFileNameEx(hProcess, 0, Result, 300)<br>hProcess:为进程句柄。
 
unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs,ddeman, StdCtrls,unit2;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br>function GetModuleFileNameExA(hProcess: Cardinal; hModule: Cardinal; lpFilename: pChar; nSize: LongInt): LongInt; stdcall; external 'psapi.dll' name 'GetModuleFileNameExA';<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br><br>{$R *.dfm}<br><br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>fullname:array[1..1024] of char;<br>h_Wnd : HWND;<br> &nbsp;prID, hProcess : DWORD;<br>begin<br>GetWindowThreadProcessId(窗口句并,@prID);<br><br>hProcess:=OpenProcess(PROCESS_ALL_ACCESS,BOOL(0),prID);<br><br><br><br>GetModuleFileNameExA(hProcess,0,@fullname,1024);<br><br><br>showmessage(fullname);<br><br>CloseHandle(hProcess);<br>end;<br><br>end.
 
to:wenyian0928!<br> &nbsp;你是知道的,就是不愿意帮帮我!
 
大唐电信不是把代码都贴出来了吗。
 
学习中, 先照抄一边代码:<br>function getModuleFileNameExA(hProcess: Carinal; hModule:Cardinal;<br><br>ipfilename:pChar; nSize:LongInt):longInt; stdcall; external 'psapi.dll'<br>name 'GetModuleFileNameExa';<br><br>begin<br> &nbsp;getwindowThreadprocessId(窗口句柄,@prId) ;// prId:dword<br> &nbsp;hprocess:=Openprocess(PROCESS_ALL_ACCESS,bool(0),prId); //hprocess:dwprd<br> getModuleFileNameExA(hprocess,0,fullname,1024); <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // fullname:array[1..1024] of char<br> &nbsp;顺便问一下 ,bool(0) 是false的意思吗? 这个是不是需要自己写代码啊?<br>我是菜鸟但肯学!
 
hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, FALSE, prId);<br>bool(0) 是false的意思.
 
to 大唐电信 兄:<br> &nbsp; 小家子气作风!!<br>getModuleFileNameExA 在哪里!<br><br>大度些,再大度些!
 
function GetModuleFileNameEx(hProcess: Cardinal; hModule: Cardinal; lpFilename: pChar; nSize: LongInt): LongInt; stdcall; external 'psapi.dll' name 'GetModuleFileNameExA';<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> &nbsp;pID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : DWORD;<br> &nbsp;hProcess &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Cardinal;<br> &nbsp;Path &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: pChar;<br>begin<br> &nbsp;GetMem(Path, 255);<br> &nbsp;GetwindowThreadprocessId(Form1.Handle, pID);<br> &nbsp;hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, FALSE, pId);<br> &nbsp;GetModuleFileNameEx(hProcess, 0, Path, 255);<br> &nbsp;Button1.Caption := Path;<br> &nbsp;FreeMem(Path);<br>end;
 
to 大唐电信: 兄弟错怪了,我以为function GetModuleFileNameEx(hProcess: Cardinal; hModule: Cardinal; lpFilename: pChar; nSize: LongInt): LongInt; stdcall; external 'psapi.dll' name 'GetModuleFileNameExA';<br>是你自己扩充了GetModuleFileName!原来是psapi.dll 提供现成的!<br><br>to wenyian0928: 谢谢你你们!<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--------------------问题完美解决--------------
 
后退
顶部