Advertisement
Guest User

proc

a guest
Aug 27th, 2012
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. uses ... TlHelp32;
  2. function GetModuleFileName(pID: DWORD): string;
  3. var
  4. hSnapshot: THandle;
  5. mEntr: tagMODULEENTRY32;
  6. begin
  7. result:= 'noname';
  8. hSnapshot:= CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pID);
  9. if hSnapshot <> INVALID_HANDLE_VALUE then
  10. try
  11. mEntr.dwSize:= SizeOf(mEntr);
  12. if Module32First(hSnapshot, mEntr) then
  13. result:= mEntr.szExePath;
  14. finally
  15. CloseHandle(hSnapshot)
  16. end;
  17. end;
  18.  
  19. function ParentProcName: string;
  20. var
  21. pID: DWORD;
  22. hSnapshot: THandle;
  23. ProcessEntry: TProcessEntry32;
  24. begin
  25. result:= 'noname';
  26. hSnapshot:= CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  27. if hSnapshot <> INVALID_HANDLE_VALUE then
  28. try
  29. ProcessEntry.dwSize:= SizeOf(ProcessEntry);
  30. if Process32First(hSnapshot, ProcessEntry) then begin
  31. pID:= GetCurrentProcessID;
  32. repeat
  33. if ProcessEntry.th32ProcessID = pID then begin
  34. result:= GetModuleFileName(ProcessEntry.th32ParentProcessID);
  35. Break;
  36. end;
  37. until not Process32Next(hSnapshot, ProcessEntry);
  38. end;
  39. finally
  40. CloseHandle(hSnapshot)
  41. end;
  42. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement