Hi Greg,
And I believe that is the case as well as with using
'Environment.SetEnvironmentVariable("Foo", string.Format("{0:HHmmss}",
DateTime.Now), EnvironmentVariableTarget.User);'. The variable will be
available in new processes for that user, not the current process (my emphasis
added):If target is User, the environment variable is stored in the Windows registry key reserved for the current user. It is also copied to instances of Windows Explorer that are running as the current user. The environment variable is then inherited by any new processes that the user launches from Windows Explorer. Similarly, if target is Machine, the environment variable is stored in the Windows registry key reserved for the local computer. It is also copied to all instances of Windows Explorer. The environment variable is then inherited by any new processes that are launched from Windows Explorer. I used LINQPad to execute the statement (to save me from having to build a console app) and then, and only then, I created a new command window and the variable was inherited. [cid:[email protected]] Does the setting of the environment variable have to be done by the application executed in the same bat/cmd file (same process) as the subsequent use of the variable? If not, then your solution is fine provided you spawn your second process after setting it with the first. Cheers, Chris From: [email protected] [mailto:[email protected]] On Behalf Of Greg Keogh Sent: Sunday, 23 October 2011 2:46 PM To: 'ozDotNet' Subject: RE: Setting DOS environment variables Could you use setx? I think its an old sysinternals tool. I hadn't noticed that tool before. But sadly: Setx writes variables to the master environment in the registry. Variables set with setx variables are available in future command windows only, not in the current command window. Greg
<<inline: image003.jpg>>
