unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Registry,
Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
Edit1 : TEdit;
Edit2 : TEdit;
Button1 : TButton;
Label1 : TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
Type
tEnviromentOwner = (eoUser, eoSystem);
var
Form1: TForm1;
Const
cEnviromentOwnerRegPlace :
Array [tEnviromentOwner]
of Record
Root: HKEY;
Key:
String
End = (
(Root: HKEY_CURRENT_USER;
Key: '
Environment'),
(Root: HKEY_LOCAL_MACHINE;
Key: '
SYSTEM\CurrentControlSet\Control\Session Manager\Environment')
);
implementation
{$R *.dfm}
Function GetSystemWideEnvironmentVariable (aOwner: tEnviromentOwner; aName:
String):
String;
Var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
With Reg, cEnviromentOwnerRegPlace [aOwner]
Do
Try
RootKey := Root;
OpenKey (Key, False);
Result := ReadString (aName);
Finally
Free;
End;
end;
Function GetEnv(regarea, varname :
STRING ):
String;
VAR
retstr :
String;
BEGIN
IF AnsiUpperCase(regarea) = '
USER'
THEN
retstr := GetSystemWideEnvironmentVariable (eoUser, varname)
ELSE IF AnsiUpperCase(regarea) = '
SYSTEM'
THEN
retstr := GetSystemWideEnvironmentVariable (eoSystem, varname)
ELSE
retstr := '
';
Result := retstr;
END;
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption := GetEnv( Edit1.Text , Edit2.Text );
end;
end.