Board index » delphi » Accessing the dos environment

Accessing the dos environment

Is there a nice Delphi function that will return the value of an
environmental variable ?
I've been playing with getdosenv from the windows api - but can only get
back the first env. string.
I'm using delphi 1 and want to be able to read the dos environment under
both windows 3.1 and 95.

Please email, as well as post.

 

Re:Accessing the dos environment


Quote
Stephen Brydges wrote:

> Is there a nice Delphi function that will return the value of an
> environmental variable ?
> I've been playing with getdosenv from the windows api - but can only get
> back the first env. string.
> I'm using delphi 1 and want to be able to read the dos environment under
> both windows 3.1 and 95.

> Please email, as well as post.

GetDosEnv does return the complete environment, as multiple 0-terminated
strings, and a final 0 to terminate the list.

e.g.
'COMSPEC=C:\COMMAND.COM'+#0+'PATH=C:\WINDOWS'+#0+#0

You'll have to do something like this:

procedure GetEnvStrings (list : TStrings);
var
  p       : PChar;
begin
  p := GetDosEnvironment;
  while (StrPas(p)<>'') do begin
    list.Add(StrPas(p));
    p := POINTER(LONGINT(p) + StrLen(p) + 1);
  end;
end;

--
Need a custom component? Late on a project? Could use an util?
DOS Device driver? A VxD? NT drivers or services? Applications of any
kind?
Low rates, fast delivery!

When responding to news postings, please CC a copy to my email address.
Thanks.
Erik Sperling Johansen <e...@info-pro.no>

Re:Accessing the dos environment


Quote
Stephen Brydges <stephen.bryd...@nottingham.ac.uk> wrote:
>Is there a nice Delphi function that will return the value of an
>environmental variable ?
>I've been playing with getdosenv from the windows api - but can only get
>back the first env. string.
>I'm using delphi 1 and want to be able to read the dos environment under
>both windows 3.1 and 95.

GetDosEnv returns a #0 separated list... Just step over the first #0
(MyPChar := MyPChar + 1;) and wait for a #0#0 signalling the end of
the environment.
--
Stefan.Hoffmeis...@Uni-Passau.de
http://www.rz.uni-passau.de/~w4hoff01/
University of Passau, Bavaria, Germany

Other Threads