An environment table is a dictionary of name-value pairs
(case-insensitive) - basically, a hashtable. It is global to a process and
can be accessed in .NET by using the Environment class (e,g
GetEnvironmentVariables).
Each process you are running in has its own env table, and each child
process inherits a table from its parent process. When you launch an
external process using the Process class you can add name-value pairs to the
table that the target process will see by adding entries to the
StartInfo.Environment property. These entries are added to the entries that
originate from the parent's table.
Child processes can retrieve values from the table several ways. The most
direct for .net apps is to use Environment.GetEnvironmentVariable("VarName")
where "VarName" is the key. If the dictionary contains an entry where the
key=VarName and the value is "envValue", then the method returns "envValue".
Another way to use it is to use the method
Environment.ExpandEnvironmentVariables. For example, for...
string envVal = Environment.ExpandEnvironmentVariables("This is a string
with an embedded %VarName%")
the string returned will be "This is a string with an embedded envValue"
This API method uses the char % to denote the beginning and end of each key,
and will replace all that it founds with its value. If the key does not
exist in the table then an empty string will be returned, effectively
erasing the entry.
Win32 Batch files can access these by using the % syntax. For example, you
can use this to shell out to a batch file...
ProcessStartInfo psi = new ...
psi.FileName = "BatchFile.bat";
psi.EnvironmentVariables.Add("CopyHere","C:\ TheTarget");
....
Process p = new ...
p.StartInfo = psi;
psi.Start()
The batch file can contain a command like this...
copy D:\TheSource\*.* %CopyHere%\*.*
All files in D:\TheSource\*.* will be copied to C:\ TheTarget
Obviously this left out a lot of detail and error checking, but it should
give you some idea of what it does and how to start using it.