Einzelnen Beitrag anzeigen

DRPEnc

Registriert seit: 20. Feb 2004
Ort: Noch unterm Mond
126 Beiträge
 
#17

Re: Process Priorität setzen - als Variable...

  Alt 19. Mär 2004, 23:08
Delphi-Quellcode:
unit Priority;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function RunProcess(FileName: string; ShowCmd: DWORD; wait: Boolean; ProcID: PDWORD;const AdwProcessPriority : DWORD): Longword;
var
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
begin
  FillChar(StartupInfo, SizeOf(StartupInfo), #0);
  StartupInfo.cb := SizeOf(StartupInfo);
  StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
  StartupInfo.wShowWindow := ShowCmd;
  if not CreateProcess(nil,
    @Filename[1],
    nil,
    nil,
    False,
    CREATE_NEW_CONSOLE or
    NORMAL_PRIORITY_CLASS,
    nil,
    nil,
    StartupInfo,
    ProcessInfo)
    then
      Result := WAIT_FAILED
  else
  begin
    SetPriorityClass(ProcessInfo.hProcess,AdwProcessPriority);
    if wait = FALSE then
    begin
      if ProcID <> nil then ProcID^ := ProcessInfo.dwProcessId;
      exit;
    end;
    WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess, Result);
  end;
  if ProcessInfo.hProcess <> 0 then
    CloseHandle(ProcessInfo.hProcess);
  if ProcessInfo.hThread <> 0 then
    CloseHandle(ProcessInfo.hThread);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items.AddObject('Idle Priorität',TObject(IDLE_PRIORITY_CLASS));
ComboBox1.Items.AddObject('Normale Priorität',TObject(NORMAL_PRIORITY_CLASS));
ComboBox1.Items.AddObject('High Priorität',TObject(HIGH_PRIORITY_CLASS));
end;

procedure TForm1.Button1Click(Sender: TObject);
var ProcID, SetPriorityClass: Cardinal;
P: TCaption ;
    begin
//RunBatch

ProcID := 0;
P := Edit1.text;
//SetPriorityClass := 'NORMAL_PRIORITY_CLASS' ;
RunProcess('Test.bat', SW_SHOW, True, @ProcID, Cardinal(ComboBox1.Items.Objects[ComboBox1.ItemIndex]) );
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
if form1.ComboBox1.ItemIndex=0 then form1.Edit1.Text:='IDLE_PRIORITY_CLASS';
if form1.ComboBox1.ItemIndex=1 then form1.Edit1.Text:='NORMAL_PRIORITY_CLASS';
if form1.ComboBox1.ItemIndex=2 then form1.Edit1.Text:='HIGH_PRIORITY_CLASS';
end;

end.
Da ist noch fett der Wurm drin...
CU

DRPEnc
  Mit Zitat antworten Zitat