unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  uchwytOkna :THandle;
  identProcesu :DWORD;
  uchwytProcesu :THandle;
begin
uchwytOkna := FindWindow(nil,PCHar(Edit1.Text));
if (IsWindow(uchwytOkna)) then
  begin
  identProcesu:=0;
  GetWindowThreadProcessId(uchwytOkna, @identProcesu);
  uchwytProcesu := OpenProcess(PROCESS_SET_INFORMATION, FALSE, identProcesu);
  if (uchwytProcesu<>0) then
    begin
    if (not SetPriorityClass(uchwytProcesu,IDLE_PRIORITY_CLASS)) then
      ShowMessage('Nie można zmienić priorytetu ('+Edit1.Text+')');
    CloseHandle(uchwytProcesu);
    end;
  end
  else
  ShowMessage('Okno o podanej nazwie nie istnieje ('+Edit1.Text+')');
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  uchwytOkna :THandle;
  identProcesu :DWORD;
  uchwytProcesu :THandle;
begin
uchwytOkna := FindWindow(nil,PCHar(Edit1.Text));
if (IsWindow(uchwytOkna)) then
  begin
  identProcesu:=0;
  GetWindowThreadProcessId(uchwytOkna, @identProcesu);
  uchwytProcesu := OpenProcess(PROCESS_TERMINATE, FALSE, identProcesu);
  if (uchwytProcesu<>0) then
    begin
    if (not TerminateProcess(uchwytProcesu,0)) then
      ShowMessage('Nie można zabić procesu ('+Edit1.Text+')');
    CloseHandle(uchwytProcesu);
    end;
  end
  else
  ShowMessage('Okno o podanej nazwie nie istnieje ('+Edit1.Text+')');
end;

end.
