Re: Change environment for the current console session

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



You can't change the environment for the console. When Microsoft does this, for things
like doing DDK builds, we find there are special batch environments for each kind of
build, which set the environment variables. These are activated by using the /k option,
e.g., the shortcut properties for one of the DKK build commands is:

C:\WINDOWS\SYSTEM32\CMD.EXE /k C:\WINDDK\2600~1.110\bin\setenv.bat C:\WINDDK\2600~1.110
chk

The /k option indicates that the following information is a command line to be run. This
sets the environment variables for that console session. This appears to be the way to
accomplish it when you need it.
joe


On Mon, 6 Jun 2005 12:46:07 -0400, "Maximus" <maximus@xxxxxxxxxxxxx> wrote:

>Hi all,
>
>I need to set the environment variables for the current console session in a
>console program I am working on. The environment variables should be set for
>the current console session. I tried SetEnvironmentVairables and putenv
>functions but they only set the variables for the current process, not the
>console. How to do it. Thanks in advance.
>

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Setting environment variables of current process by batch file
    ... I have a batch file that executes some very complicated logic. ... I've written and have the resulting environment be part of the ... But whenever I spawn a process from my console ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: GETMSG rutine Abend 0C4 Reason 17 in REXX Called with IRXJCL
    ... I believe that GETMSG is having the vapors because a "CONSOLE" environment has not been established; granted, it should NOT die with an ABEND. ...
    (bit.listserv.ibm-main)
  • Setting console parameters for PXE Booting
    ... environment for setting up our FreeBSD systems. ... specify the console terminal type i.e. VT100 etc. so that it doesn't ... When it sits there waiting for the input the install hangs waiting, ...
    (freebsd-questions)
  • Re: Great SWT Program
    ... in your environment finds it odd, that suggests that everyone in your ... including the machine's console and any remotely-connected ... I wouldn't be surprised that the POSIX standard doesn't mention ... and no standard-conforming system may add others", ...
    (comp.lang.java.programmer)
  • Re: Setting environment variables of current process by batch file
    ... I've written and have the resulting environment be part of the ... original process. ... But whenever I spawn a process from my console ... I can think of at least two other ways to accomplish the goal of setting the environment variables for the new process, but given that doing so is already supported by the System.Diagnostics.Process class, why bother? ...
    (microsoft.public.dotnet.languages.csharp)