已知进程句柄,如何获取该进程执行程序的大小?(100分)

  • 主题发起人 主题发起人 默默无闻
  • 开始时间 开始时间

默默无闻

Unregistered / Unconfirmed
GUEST, unregistred user!
通过快照已获取该进程句柄,且只能获取到该程序的名称,不能得到完整的程序路径。<br><br>如何获取该执行程序的大小、生成时间等信息?
 
procedure ShowProcessinfo(Processid:Cardinal);<br>var<br>&nbsp; h: THandle;<br>&nbsp; fileName: string;<br>&nbsp; iLen: integer;<br>&nbsp; hMod: HMODULE;<br>&nbsp; cbNeeded: DWORD;<br>begin<br>&nbsp; h := OpenProcess(PROCESS_ALL_ACCESS, false,Processid ); <br>&nbsp; if h &gt; 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; if EnumProcessModules(h, @hMod, sizeof(hMod), cbNeeded) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; SetLength(fileName, MAX_PATH);<br>&nbsp; &nbsp; &nbsp; iLen := GetModuleFileNameEx(h, hMod, PCHAR(fileName), MAX_PATH);<br>&nbsp; &nbsp; &nbsp; if iLen &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; SetLength(fileName, StrLen(PCHAR(fileName)));<br>&nbsp; &nbsp; &nbsp; &nbsp; ShowMessage(fileName);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; CloseHandle(h);<br>&nbsp; end;<br>end;<br><br>procedure TMainform.Button2Click(Sender: TObject);<br>var<br>&nbsp; PE: TProcessEntry32;<br>&nbsp; Found: boolean;<br>&nbsp; h: THandle;<br>begin<br>&nbsp; h := CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);<br>&nbsp; PE.dwSize := SizeOf(TProcessEntry32);<br>&nbsp; Found := Process32First(h, PE);<br>&nbsp; while Found do<br>&nbsp; begin<br>&nbsp; &nbsp; if PE.szExeFile = 'WINWORD.EXE' then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; [red]ShowProcessinfo(PE.th32ProcessID);[/red]<br>&nbsp; &nbsp; &nbsp; Exit; //找到有Word的进程就退出<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; Found := Process32Next(h, PE);<br>&nbsp; end;<br>&nbsp; ShellExecute(Handle, 'open', 'WINWORD.EXE', '', '', SW_SHOW); //没找到就运行<br>end;
 
3Q,得到路径了。
 
后退
顶部