Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi SetPriorityClass Problem (https://www.delphipraxis.net/54814-setpriorityclass-problem.html)

glunzl 11. Okt 2005 21:29


SetPriorityClass Problem
 
Hallo!

Ich möchte einen Prozess auf eine andere Priorität bringen. Ich habe mir die Threads zum Thema Prozess Prioritätsänderung durchgelesen, habe bei der Umsetzung aber noch ein Problem:

Mit folgender Funktion hole ich mir das Handle von notepad.exe und speicher mir diese in eine globale Integer Variable mit Namen "ProcessID", da ich den Wert nochmal brauche (funktioniert soweit auch).
Delphi-Quellcode:
function TForm1.GetProcessID(sProcName: String): Integer;
var
  hProcSnap: THandle;
  pe32: TProcessEntry32;
begin
  result := -1;
  hProcSnap := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);  // Snapschot erstellen
  if hProcSnap = INVALID_HANDLE_VALUE then exit;                 // Snapshot erstellt?

  pe32.dwSize := SizeOf(ProcessEntry32);

  { wenn es geklappt hat }
  if Process32First(hProcSnap, pe32) = true then
    { und los geht's: Prozess suchen}
    while Process32Next(hProcSnap, pe32) = true do
    begin
      if pos(sProcName, pe32.szExeFile) <> 0 then
        result := pe32.th32ProcessID;
    end;
  CloseHandle(hProcSnap);
end;
Anschließend versuche ich mit
Delphi-Quellcode:
  SetPriorityClass(ProcessID,(IDLE_PRIORITY_CLASS));
die Prio zu ändern. Im Taskmanager bleibt die Prio von notepad.exe aber auf "Normal".

Wenn ich hingegen
Delphi-Quellcode:
  SetPriorityClass(GetCurrentProcess,(IDLE_PRIORITY_CLASS));
benutze, wird meine eigene Anwendung (Projekt.exe) auf "Niedrig" gestellt.

Warum funktioniert das nicht mit dem geholten Handle von notepad.exe (notepad.exe läuft auch)

Gruß und Dank
Michael

Dax 11. Okt 2005 21:41

Re: SetPriorityClass Problem
 
Du übergibst ja auch die ProzessID von Notepad, nicht das Prozesshandle, das erwartet wird.. Deinen Code musst du dahingehend umändern.


Alle Zeitangaben in WEZ +1. Es ist jetzt 12:44 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz