Get, no Set 

 

  _____  

Ian Thomas
Victoria Park, Western Australia

  _____  

From: [email protected] [mailto:[email protected]]
On Behalf Of David Kean
Sent: Wednesday, October 26, 2011 8:24 AM
To: ozDotNet
Subject: RE: Setting DOS environment variables

 

Have you tried ProcessStartInfo.EnvironmentVariables?

 

http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.
environmentvariables.aspx

 

 

From: [email protected] [mailto:[email protected]]
On Behalf Of Greg Keogh
Sent: Saturday, October 22, 2011 6:49 PM
To: 'ozDotNet'
Subject: Setting DOS environment variables

 

Several years ago I tried to find a way of setting (creating) DOS
environment variables in code and then using the values in batch files. I
remember I failed because the variables only existed for the duration of the
process. I had a fresh look at this problem today and was thrilled to see a
3rd argument added to the SetEnvironmentVariable
<http://msdn.microsoft.com/en-us/library/system.environment.setenvironmentva
riable.aspx>  method. I wrote a console app with this single line of code:

 

Environment.SetEnvironmentVariable("Foo", string.Format("{0:HHmmss}",
DateTime.Now), EnvironmentVariableTarget.User);

 

In a bat file I then called this app followed by a "set f" command. But
sadly the Foo value is not present. I tried setting target to Machine, but
this requires admin privileges to write to HKLM. Even more sadly it does
work either because it seems to write the reg entry but the new value is not
immediately picked up by the batch file.

 

Does anyone know of a trick to programmatically set environment variables
for use in a bat file?

 

Greg

 

 

Reply via email to