Branko BURDIAN wrote:
> Simple example;
>
> program SetEnv;
> {$APPTYPE CONSOLE}
> uses
> Windows;
> procedure SetEnvVariable(const AName, AValue: string);
> begin
> if Trim(AValue) = '' then
> SetEnvironmentVariable(PChar(AName), nil)
> else
> SetEnvironmentVariable(PChar(AName), PChar(AValue));
> end;
> begin
> SetEnvVariable('foobar', 'abcdef');
> end;
>
> Compile and run program:
>
> C:\>SetEnv <Enter>
> C:\>set foobar <Enter>
> foobar=abcdes <= This is the result of "set foobar" command
>
> Result of runing program SetEnv is same as if you execute
> "set foobar=abcdef" (without ") on command prompt!!
Are you sure about that?
I don't think you actually ran the code you show above.
Each process inherits a *copy* of its parent's environment.
Modifications to the environment are not propagated back to the parent
process. When you run SetEnv, it does not modify the environment of
cmd.exe. The "set" command is a built-in command of cmd.exe, so when you
use it, you're making cmd.exe modify its own environment. Batch files,
likewise, are executed by the command interpreter, not by a separate
process, so batch files can modify the environments of the processes
that execute them.
--
Rob