Get all Environment Strings (Views: 100)
Sometimes you want to show the user the current settings on his/her machine. One of the vital information are the Environment Strings. The Windows API gives us an efficient set of funcitons to access these
Actually, it is really easy to access the Windows Environment Strings. The Windows API defines a function called "GetEnvironmentStrings" to return a double-null terminated buffer filled with null terminated strings seperating all environment variables.
The following procedure will takes a string list as parameter and fill it with all environment variables returned. It will parse the buffer string by string, setting a pointer behind every string returned in order to retrieve the next one.
I hope this will help you.
procedure LoadEnvironmentStrings(Strings: TStrings);
AllStrings, CurrentString: PChar;
AllStrings := GetEnvironmentStrings;
if AllStrings <> nil then
CurrentString := AllStrings;
while True do
if CurrentString = #0 then
procedure GetEnvStringsList(EnvStr: TStringList);
PEnv, PCopyEnv: pchar;
PEnv := GetEnvironmentStrings;
PCopyEnv := PEnv;
if PCopyEnv <> nil then
inc(PCopyEnv, StrLen(PCopyEnv) + 1);
until PCopyEnv^ = #0;
PCopyEnv := nil;
<< Back to main page