我现在得到一个别的程序的实列句柄,现在我想根据该句柄找到该程序 的文件名和路径,(在线等待!)

Shikari 2002-12-04 03:23:28
我现在得到一个别的程序的实列句柄,现在我想根据该句柄找到该程序 的文件名和路径,(在线等待!)
...全文
61 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sowine 2002-12-04
  • 打赏
  • 举报
回复

up!!!!!1
智商无下限 2002-12-04
  • 打赏
  • 举报
回复
诶呀吗呀!好长阿!!!
toplor 2002-12-04
  • 打赏
  • 举报
回复
hWindow为窗口的句柄

function uhfGetWindowModuleFileName(hWindow:THandle): string;
type
TGetModuleFileNameEx=function(hProcess:THandle;hMod:THandle;szBaseName:PChar;iSize:Integer):Bool;stdcall;
TEnumProcessModules=function(hProcess:THandle;var hMod:THandle;cSize:Cardinal;var cSizeOut:Cardinal):Bool;stdcall;
var
cProcID: DWORD;
hSSHandle: THandle;
bContinue: Boolean;
rProcEntry: TProcessEntry32;
hProcHandle: THandle;
szName: array[0..1024] of Char;
GetModuleFileNameEx: TGetModuleFileNameEx;
EnumProcessModules: TEnumProcessModules;
hModPSAPI: THandle;
hMod: THandle;
cDummy: Cardinal;
begin
result:='';
If Win32Platform = VER_PLATFORM_WIN32_NT then
begin
hModPSAPI := LoadLibrary('psapi.dll');
if hModPSAPI <> 0 then
begin
GetModuleFileNameEx := GetProcAddress(hModPSAPI, 'GetModuleFileNameExA');
EnumProcessModules := GetProcAddress(hModPSAPI, 'EnumProcessModules');
if Assigned(GetModuleFileNameEx) and Assigned(EnumProcessModules) then
begin
if GetWindowThreadProcessID(hWindow, @cProcID) <> 0 then
begin
hProcHandle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, cProcID);
if hProcHandle <> 0 then
begin
try
if EnumProcessModules(hProcHandle, hMod, sizeof(hMod), cDummy)then
if GetModuleFileNameEx(hProcHandle, 0, @szName, sizeof (szName))then
Result := StrPas(szName)
finally
CloseHandle(hProcHandle)
end;
end;
end;
end;
FreeLibrary(hModPSAPI);
end;
end
else begin
if GetWindowThreadProcessID(hWindow, @cProcID) <> 0 then
begin
hSSHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSSHandle <> INVALID_HANDLE_VALUE) then
begin
rProcEntry.dwSize := Sizeof(rProcEntry);
bContinue := Process32First(hSSHandle, rProcEntry);
while bContinue do
begin
if rProcEntry.th32ProcessID = cProcID then
begin
Result := rProcEntry.szExeFile;
Break;
end;
bContinue := Process32Next(hSSHandle, rProcEntry);
end;
CloseHandle(hSSHandle);
end;
end;
end;
end;

-------------------------------------------------------------
风过西窗客渡舟船无觅处
年年一川新草遥看却似旧
lws0472 2002-12-04
  • 打赏
  • 举报
回复
var
buff : array[0..254] of char;
dd : string;
begin
GetModuleFileName(yourHandle,@buff,255);
dd := strpas(@buff);
showmessage(dd);
end;

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧