How can I create and run a process from my program with the ability to set the priority of the process?
This is what I have so far:
const
LOW_PRIORITY = IDLE_PRIORITY_CLASS;
//BELOW_NORMAL_PRIORITY = ???
NORMAL_PRIORITY = NORMAL_PRIORITY_CLASS;
//ABOVE_NORMAL_PRIROTY = ???
HIGH_PRIORITY = HIGH_PRIORITY_CLASS;
REALTIME_PRIORITY = REALTIME_PRIORITY_CLASS;
procedure RunProcess(FileName: string; Priority: Integer);
var
StartInfo: TStartupInfo;
ProcInfo: TProcessInformation;
Done: Boolean;
begin
FillChar(StartInfo,SizeOf(TStartupInfo),#0);
FillChar(ProcInfo,SizeOf(TProcessInformation),#0);
StartInfo.cb := SizeOf(TStartupInfo);
try
Done := CreateProcess(nil, PChar(FileName), nil, nil,False,
CREATE_NEW_PROCESS_GROUP + Priority,
nil, nil, StartInfo, ProcInfo);
if not Done then
MessageDlg('Could not run ' + FileName, mtError, [mbOk], 0);
finally
CloseHandle(ProcInfo.hProcess);
CloseHandle(ProcInfo.hThread);
end;
end;
The above code works in that I can set the priority of the executed process. But see the image below of the Windows Task Manager:
You can set more options such as Below Normal and Above Normal which is what I want to also be able to set. Looking through Windows.pas I see no such value.
How can I create and run my process with those extra parameters?
Thanks :)