473,508 Members | 3,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

StartInfo.EnvironmentVariables ?

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
2 5028
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6629
by: Szymon Madejczyk | last post by:
example code: public class envtest { public static void Main() { System.Diagnostics.Process proc = System.Diagnostics.Process.GetCurrentProcess(); string env =...
3
787
by: Jeff Jarrell | last post by:
I have an object to execute a process. its intent is to do a simple execute and capture stdin and stdout. Nothing fancy, not for long processes. simple. I expect to typically use it with a fully...
4
6541
by: James Pang | last post by:
-- Tech Servant James Pang.
1
6693
by: James Pang | last post by:
myProcess.StartInfo.FileName==@"C:\WINDOWS\system32\ping.exe 10.0.0.1"; //this will not work cant find file name... myProcess.StartInfo.FileName==@"C:\WINDOWS\system32\ping.exe"; //this works...
2
5098
by: David | last post by:
I'm opening a cmd window to run an ftp process. It's easy enough to close the process (.close()), but the cmd window won't close unless I go out to the window and type 'quit'. How can I send a...
2
3573
by: Alan T | last post by:
I use Process.StartInfo to configure the process: Process myProcess = new Process(); myProcess.StartInfo.FileName = aProg; myProcess.StartInfo.Arguments = aArgument; ...
2
7109
by: Alan T | last post by:
How do I make it does NOT appear on the task bar when it is started?
4
1909
by: ceh | last post by:
Hi, I'm using c# vs 2005 win xp pro sp2. I create a cmd prompt with pInvoke via CreateProcessWithLogonW Taskmgr shows that cmd instance running as that user. I type set in that cmd window and it...
1
5466
by: Analizer1 | last post by:
Hi...any body know what the max string length size when using Process.StartInfo.Arguments Example Process.StartInfo.FileName = "Wzzip.exe" Process.StartInfo.Arguments =...
0
7228
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7332
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7058
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5635
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
426
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.