Aber ersetze ich notepad.exe (oder ein anderes einthreadiges Programm wie calc und was sonst alles so
gerne als Demo genommen wird) durch Excel.exe oder Windword.exe oder Firefox.exe dann scheitert
ProgramID(..), das dann immer -1 zurückgibt und damit die Ermittlung des Processhandles scheitert.
Kann man das ProcessHandle immer korrekt ermitteln ?
Code: Alles auswählen
Procedure SetPriority(ProgramID.l, PriorityLevel.l)
Protected ProcessHandle.l
ProcessHandle = OpenProcess_(#PROCESS_DUP_HANDLE + #PROCESS_SET_INFORMATION, #True, ProgramID)
If ProcessHandle
SetPriorityClass_(ProcessHandle, PriorityLevel)
CloseHandle_(ProcessHandle)
EndIf
EndProcedure
Result = RunProgram("Notepad.exe", "", "", #PB_Program_Open)
If Result
Debug Result
Debug ProgramID(Result)
SetPriority(ProgramID(Result), #IDLE_PRIORITY_CLASS) ; niedrige Prioritätsstufe
MessageRequester("","")
KillProgram(Result)
CloseProgram(Result)
EndIf