StartInfo.EnvironmentVariables ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • XxLicherxX

    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

  • Lloyd Dupont

    #2
    Re: StartInfo.Envir onmentVariables ?

    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 " <goldhors64@aol .com> wrote in message
    news:1132423298 .778163.313340@ z14g2000cwz.goo glegroups.com.. .[color=blue]
    > 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
    >[/color]


    Comment

    • David Levine

      #3
      Re: StartInfo.Envir onmentVariables ?

      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
      GetEnvironmentV ariables).

      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.Envir onment 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.Get EnvironmentVari able("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.Exp andEnvironmentV ariables. For example, for...

      string envVal = Environment.Exp andEnvironmentV ariables("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...

      ProcessStartInf o psi = new ...
      psi.FileName = "BatchFile.bat" ;
      psi.Environment Variables.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 " <goldhors64@aol .com> wrote in message
      news:1132423298 .778163.313340@ z14g2000cwz.goo glegroups.com.. .[color=blue]
      > 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
      >[/color]


      Comment

      Working...