Environment variables: 64 vs 32 bit cmd

MaeSiuS
2011-08-31
2013-06-12
  • MaeSiuS
    MaeSiuS
    2011-08-31

    Hi all,
    this time a question about environment variables and their differences on 32 vs 64 bit versions of cmd.exe in console. Thread Problem with environment variables in b140 focuses on user variable handling.
    Console reports the 64bit value for %ProgramFiles%. I've setup console to use C:\Windows\System32\cmd.exe which returns C:\Program Files for %ProgramFiles%.
    In fact, console seems to use C:\Windows\SysWOW64\cmd.exe which returns C:\Program Files (x86) for %ProgramFiles%
    The value of %ProgramFiles% breaks my scripts that run perfectly on 32bit cmd but fail on 46 bit cmd.
    console.xml contains:

    <tab title="CMD" use_default_icon="0">
        <console shell="C:\WINDOWS\system32\cmd.exe" init_dir="C:\" run_as_user="0" user=""/>
        <cursor style="11" r="255" g="255" b="255"/>
        <background type="2" r="0" g="0" b="0">
            <image file="" relative="0" extend="0" position="0">
                <tint opacity="172" r="0" g="0" b="0"/>
            </image>
        </background>
    </tab>
    

    Does console really refuse to use the version of cmd.exe that it has been told to use? ==> Bug
    Or does console make any weird environment variable transformations at startup? ==> Feature ;-)
    I run console by calling a small script from the "Windows run dialog" (WIN+R)
    How can this problem be fixed?

    Btw. I'm using windows 7 enterprise (64 bit) right now.

    Regards
    Matthias

     
  • MaeSiuS
    MaeSiuS
    2011-08-31

    Hi again,
    for a "quick" fix, i could replace %ProgramFiles% through %ProgramW6432% in all my scripts. See: WOW64 Implementation Details.
    But this does not fix the mis-behaviour of console's variable handling.

    Regards
    Matthias

     
  • MaeSiuS
    MaeSiuS
    2011-09-01

    Console mixes up the 32 and 64 bit executables of cmd.exe.
    Using processExplorer from sysinternals to investigate:
    Console.exe spawns a child process for every tab i.e. cmd.exe. DoubleClick on cmd.exe to open its properties. The process image shows

    Path: C:\Windows\SysWOW64\cmd.exe

    and

    Command line: C:\WINDOWS\system32\cmd.exe

    The Command line is correct and holds value that is specified in Console's settings

    Edit > Settings > Tabs > Main > Shell > Shell
    

    in fact the cmd.exe from Path seems to be exectued.
    Looks like a bug

    Regards
    Matthias

     
  • Kirill
    Kirill
    2011-09-01

    The behaviour, you're observing, is caused by running 32-bit Console.

    Windows (rather WOW) makes 32-bit apps believe that they're accessing c:\windows\system32 whereas in fact they're accessing c:\windows\systemwow64.

    Same goes to the evnironment vars. Windows supplies Console with them, including c:\program files (x86) as %ProgramFiles%, taking into account that Console is 32-bit.

    You can try 64-bit Console, but running 32-bit shells maybe… not so smooth.