Now I'm confused too. In "My Computer", the Advanced page shows the 
environmental variables. I presume that these are global and inherited by any 
console session. These are not modified by SetEnvironmentVariable()?
 
Dave

--- On Sat, 8/16/08, Rob Kennedy <[EMAIL PROTECTED]> wrote:

From: Rob Kennedy <[EMAIL PROTECTED]>
Subject: Re: [delphi-en] Re: Set Environment Variable from Delphi Console App
To: [email protected]
Date: Saturday, August 16, 2008, 2:01 PM






Branko BURDIAN wrote:
> Simple example;
> 
> program SetEnv;
> {$APPTYPE CONSOLE}
> uses
> Windows;
> procedure SetEnvVariable( const AName, AValue: string);
> begin
> if Trim(AValue) = '' then
> SetEnvironmentVaria ble(PChar( AName), nil)
> else
> SetEnvironmentVaria ble(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
 














      

[Non-text portions of this message have been removed]

Reply via email to