unit UEnv;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var P, P0: PChar;
    S: string;
begin
 ListBox1.Clear;
 P0 := GetEnvironmentStrings;
 P := P0;
 inc(P, StrLen(P) + 1);
 while P^ <> #0
 do begin
  S := StrPas(P);
  ListBox1.Items.Add(Copy(S,0,Pos('=',S) - 1));
  inc(P, lStrLen(P) + 1);
 end;
 FreeEnvironmentStrings(P0);
 ListBox1.ItemIndex := 0;
 ListBox1Click(Sender);
end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
 Edit1.Text := GetEnvironmentVariable(ListBox1.Items[ListBox1.ItemIndex]);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 SetEnvironmentVariable(PChar(ListBox1.Items[ListBox1.ItemIndex]), PChar(Edit1.Text));
end;

end.
