// Prozess ID anhand der Exe ermitteln
function TMainFrm.GetProcessID(Exename:
string): DWORD;
var
hProcSnap: THandle;
pe32: TProcessEntry32;
begin
result := 0;
hProcSnap := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
if hProcSnap <> INVALID_HANDLE_VALUE
then
begin
pe32.dwSize := SizeOf(ProcessEntry32);
if Process32First(hProcSnap, pe32) = true
then
begin
while Process32Next(hProcSnap, pe32) = true
do
begin
if pos(Exename, pe32.szExeFile) <> 0
then
result := pe32.th32ProcessID;
end;
end;
CloseHandle(hProcSnap);
end;
end;
// Prozessorzuweisung setzen
function SetProcessAffinityMaskByID(ID, Affinity: DWORD): Boolean;
var
Handle: THandle;
begin
Result := False;
Handle := OpenProcess(PROCESS_SET_INFORMATION, False, ID);
if Handle <> 0
then
begin
Result := SetProcessAffinityMask(
Handle, Affinity);
CloseHandle(
Handle);
end;
end;
// Prozessorzuweisung ermitteln
function GetProcessAffinityMaskByID(ID: DWORD): Cardinal;
var
Handle: THandle;
aSysMask: Cardinal;
begin
Handle := OpenProcess(PROCESS_QUERY_INFORMATION, False, ID);
if Handle <> 0
then
begin
GetProcessAffinityMask(
Handle, Result, aSysMask);
CloseHandle(
Handle);
end;
end;