I use this code:
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{* Get environment variable value. Just a wrapper around Win32 API *}
function GetEnv(const Name : String; var Value : String) : Integer;
var
Buffer : array [0..1023] of char;
begin
Result := Windows.GetEnvironmentVariable(PChar(Name),
Buffer, SizeOf(Buffer));
if Result <= 0 then
Value := ''
else begin
Buffer[Result] := #0;
Value := Buffer;
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
--
[EMAIL PROTECTED]
Author of ICS (Internet Component Suite, freeware)
Author of MidWare (Multi-tier framework, freeware)
http://www.overbyte.be
----- Original Message -----
From: "Arno Garrels" <[EMAIL PROTECTED]>
To: "Borland's Delphi Discussion List" <[email protected]>
Sent: Monday, May 09, 2005 8:07 PM
Subject: How to fetch environment variables correctly
> Hello,
>
> over the past years I fetched the environment variables from the registry keys
> System: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
> Manager\Environment\
> User: HKEY_CURRENT_USER\Environment\
> However not all variables are retrieved i.e. SystemRoot is missing.
> GetEnvironmentStrings() appears to be the right win-function to call, however
> the
> comment confuses me:
>
> "Do not use the return value of GetEnvironmentStrings to get or set
> environment variables.
Instead, use the GetEnvironmentVariable and SetEnvironmentVariable functions to
access the
environment variables within this block. When the block is no longer needed, it
should be freed by
calling FreeEnvironmentStrings."
>
> How can I get all environment variables reliable? I need to store them
> temporarily and pass them
later on as environment block to CreateProcess(). Is it save to call
GetEnvironmentVariable() on
each returned name?
>
> Thanks in advance,
>
> Arno Garrels
>
>
>
> _______________________________________________
> Delphi mailing list -> [email protected]
> http://www.elists.org/mailman/listinfo/delphi
>
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi