unit DefPrnU;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
 Buffer : Array[0..255] of Char;
 S      : String;
begin
 GetProfileString('windows', 'device', ',,,', buffer, 256);
 S := StrPas(Buffer);
// Имя принтера
 Edit1.Text := Copy(S, 1, Pos(',', S)-1);
 Delete(S, 1,Pos(',', S));
// Имя драйвера
 Edit2.Text := Copy(S, 1, Pos(',', S)-1);
 Delete(S, 1,Pos(',', S));
// Порт
 Edit3.Text := S;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 WriteProfileString('windows', 'device', 'New Printer,EpsonFX80,lpt1:');
 SendMessage(HWND_Broadcast, WM_WININICHANGE, 0, 0);
end;

end.
