How to change process priority?  Download
This is a Delphi 5-7 code that changes the priority of a process running a local or remote computer. It is designed for Windows XP or higher. Please note that the calling user must have SeIncreaseBasePriorityPrivilege privilege to set the process priority to REALTIME. Without this privilege it is only possible to change priority to HIGH or lower values. This example is using TWmiConnection, TWmiQuery and TWmiMethod components from WmiSet component collection. The source code below creates and destroys the components on the fly, so it may be used in UI- and console-type applications.

const
  IDLE         = $40;
  BELOW_NORMAL = $4000;
  NORMAL       = $20;
  ABOVE_NORMAL = $8000;
  HIGH         = $80;
  REALTIME     = $100;

// this function changes process priority. 
// It may be used for local or remote host. When used for local host 
// TargetHost, UserName, Password parameters must be empty. 
// For remote computer the parameters must be: 
// TargetHost: name or IP address of the remote host, like '10.8.36.54' 
// UserName: name of the user, may include domain, like 'MOON\Administrator'; 
// Password: the user's password. 
// Handle:  a handle of a running process. 
// Priority: a new priority for the process. It must be one of the constants above. 
procedure ProcessSetPriority(TargetHost, UserName, Password: string;
                             Handle: cardinal; Priority: integer);
var
  Connection: TWmiConnection;
  Query: TWmiQuery;
  Method: TWmiMethod;
  s: string;
begin
  Query      := TWmiQuery.Create(nil);
  Connection := TWmiConnection.Create(nil);
  Method     := TWmiMethod.Create(nil);
  try
    Query.Connection := Connection;
    Method.WmiObjectSource := Query;
    Query.WQL.Text := 'select * from Win32_Process';
    Connection.MachineName := TargetHost;
    Connection.Credentials.UserName := UserName;
    Connection.Credentials.Password := Password;

     // exception may happen on Win9x, WinNT if WMI core is not installed; 
    // The provided credentials may also be invalid. 
    Connection.Connected := true;

    Query.Open;
    if not Query.Locate('Handle', Handle, []) then
      raise Exception.Create('Process not found: '+IntToStr(Handle));

    Method.WmiMethodName := 'SetPriority';
    Method.InParams.ParamByName('Priority').AsInteger := Priority;
    if Method.Execute <> 0 then
    begin
      s := Method.LastWmiErrorDescription;
      if s = '' then s := 'Error '+ IntToStr(Method.LastWmiError);
      raise Exception.Create(s);
    end;

  finally
    Method.Free;
    Query.Free;
    Connection.Free;
  end;
end;