Posted April 22, 200916 yr returns a process base (CSTR) priority by a process ID, takes care of the low-level partfunction GetProcessPri(PID: DWORD): String;var hSnap: THandle; lppe: TProcessEntry32A; szPri: String;beginlppe.dwSize := sizeof(lppe);hSnap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);if Process32FirstA(hSnap, lppe) <> False then With lppe Do begin if PID = lppe.th32ProcessID then case lppe.pcPriClassBase of 13:szPri := 'High'; 8,9, 11:szPri := 'Normal'; 6:szPri := 'Below Normal'; 4:szPri := 'Low'; end; while Process32NextA(hSnap, lppe) do if PID = lppe.th32ProcessID then case lppe.pcPriClassBase of 13:szPri := 'High'; 8,9, 11:szPri := 'Normal'; 6:szPri := 'Below Normal'; 4:szPri := 'Low'; end; end;CloseHandle(hSnap);Result := szPri;end;Returns process name by process IDfunction GetPNameByPid(PID: DWORD): String;var hSnap: THandle; lppe: TProcessEntry32A; szPName: String;beginlppe.dwSize := sizeof(lppe);hSnap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);if Process32FirstA(hSnap, lppe) <> False then With lppe Do begin if th32ProcessID = PID then szPName := szExeFile; while Process32NextA(hSnap, lppe) do if th32ProcessID = PID then szPName := szExeFile; end;CloseHandle(hSnap);Result := szPName;end;Gets a process ID by the ID of the process (useful to return parent process)function TForm1.GetPidByPid(PID: DWORD): DWORD;var hSnap: THandle; lppe: TProcessEntry32A; dwPID: DWORD;begindwPID := 0; //initializing the variablelppe.dwSize := sizeof(lppe);hSnap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);if Process32FirstA(hSnap, lppe) <> False then With lppe Do begin if th32ProcessID = PID then dwPID := th32ProcessID; while Process32NextA(hSnap, lppe) do if th32ProcessID = PID then dwPID := th32ProcessID; end;Result := dwPID;end;Returns process ID by process name (CSTR)function TForm1.GetPidByPName(Selected_Process: String): DWORD;var hSnap: THandle; lppe: TProcessEntry32A; dwPID: DWORD;begindwPID := 0; //initializing the variablelppe.dwSize := sizeof(lppe);hSnap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);if Process32FirstA(hSnap, lppe) <> False then begin if lppe.szExeFile = Selected_Process then dwPID := lppe.th32ProcessID; while Process32NextA(hSnap, lppe) do if lppe.szExeFile = Selected_Process then dwPID := lppe.th32ProcessID; end;Result := dwPID;end;
April 25, 200916 yr thanks rot1, always nice to see someone contribute delphi snippets... Im still waiting to see your search and replacee snippets in delphi
Create an account or sign in to comment