我现在得到一个别的程序的实列句柄,现在我想根据该句柄找到该程序 的文件名和路径,(在线等待!)
我现在得到一个别的程序的实列句柄,现在我想根据该句柄找到该程序 的文件名和路径,(在线等待!) 问题点数:50、回复次数:4Top
1 楼lws0472(期待2008)回复于 2002-12-04 16:16:22 得分 30
var
buff : array[0..254] of char;
dd : string;
begin
GetModuleFileName(yourHandle,@buff,255);
dd := strpas(@buff);
showmessage(dd);
end;Top
2 楼toplor(霜天晓竹)回复于 2002-12-04 17:13:40 得分 20
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;
-------------------------------------------------------------
风过西窗客渡舟船无觅处
年年一川新草遥看却似旧
Top
3 楼l0f(凌风)回复于 2002-12-04 17:21:53 得分 0
诶呀吗呀!好长阿!!!Top
4 楼sowine(恐拜狼)回复于 2002-12-04 17:33:05 得分 0
up!!!!!1Top




