0xFF Posted April 22, 2009 Posted April 22, 2009 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;
Departure Posted April 25, 2009 Posted April 25, 2009 thanks rot1, always nice to see someone contribute delphi snippets... Im still waiting to see your search and replacee snippets in delphi
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now