By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,839 Members | 2,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,839 IT Pros & Developers. It's quick & easy.

StartInfo.EnvironmentVariables ?

P: n/a
Hello everyone,

Can someone tell me what this does and how I can use it? I can't seem
to find any good examples online.

Thanks

Nov 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
it sets the environment variable of the target process
to know what's an environment variable you should have played with the
command line.
if you've played with linux you should know what it is!
otherwise try to learn about the DOS command.

To know which environment variable are set in your command line, open a Dos
Command and type:
"set" ENTER

you could alos open the prperty panel of your computer => advanced =>
environment variable

most modern windows program don't care much about environment variable
except the PATH, which tells them where to search for executable and DLL.
but, for example CL (the Microsoft C Compiler) use a big host of over
variable (being an on command line tool)

"XxLicherxX" <go********@aol.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hello everyone,

Can someone tell me what this does and how I can use it? I can't seem
to find any good examples online.

Thanks

Nov 23 '05 #2

P: n/a
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.

"XxLicherxX" <go********@aol.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hello everyone,

Can someone tell me what this does and how I can use it? I can't seem
to find any good examples online.

Thanks

Nov 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.