none
VBScript - ExpandEnvironmentStrings("%PROGRAMFILES%") Returns Different Result Between Debug and Run Mode

    Question

  • I'm debugging vbscript with Microsoft Visual Studio 2010 Professional...

    In Debug Mode:

    objShell.ExpandEnvironmentStrings("%PROGRAMFILES%") = "C:\Program Files (x86)"

    In Run Mode:

    objShell.ExpandEnvironmentStrings("%PROGRAMFILES%") = "C:\Program Files"

    What's up with that?  I need it to be the same result regardless of how the script is executing.

    Help.

    • Moved by Shanks ZenModerator Monday, October 15, 2012 2:57 AM VBScript issue (From:Visual Basic General)
    • Moved by Bill_Stewart Monday, October 15, 2012 5:16 PM Move to more appropriate forum (From:The Official Scripting Guys Forum!)
    Saturday, October 13, 2012 10:22 PM

Answers

  • In VS 2010 debug builds default to x86, so your debug exe is seeing the x86 program files.

    The release build is probably AnyCPU, which is running in 64 bits and so sees the other path.

    Change your project settings so that they both use x86 or AnyCPU. I think you lose some debugging abilities in VS2010 if your debug is not x86, such as Edit and Continue.

    • Proposed as answer by jrv Monday, October 15, 2012 11:14 AM
    • Marked as answer by Shanks ZenModerator Monday, October 22, 2012 3:09 AM
    Sunday, October 14, 2012 9:35 AM

All replies

  • In VS 2010 debug builds default to x86, so your debug exe is seeing the x86 program files.

    The release build is probably AnyCPU, which is running in 64 bits and so sees the other path.

    Change your project settings so that they both use x86 or AnyCPU. I think you lose some debugging abilities in VS2010 if your debug is not x86, such as Edit and Continue.

    • Proposed as answer by jrv Monday, October 15, 2012 11:14 AM
    • Marked as answer by Shanks ZenModerator Monday, October 22, 2012 3:09 AM
    Sunday, October 14, 2012 9:35 AM
  • Hi Rpearsall222,

    this issue is related to VBScript, in order to provide better support, I will move this thread to The Official Scripting Guys Forum!.

    Thanks for understanding!


    Shanks Zen
    MSDN Community Support | Feedback to us

    Monday, October 15, 2012 2:56 AM
  • Not a scripting issue - this is a pure issue of Visual Studio functionality. VBS under VS is used for web developpment.  This forum is an admin scripoting forum and not a web scripting forum.

    This issue can only be correctly addressed in the devleopers forum.


    ¯\_(ツ)_/¯

    Monday, October 15, 2012 11:13 AM
  • I have similar problem..

    Using Windows 7 Professional 64 bit with Excel 2013 Standard 32 bit

    In Windows there are two environment variables"

    %PROGRAMFILES% = "C:\PROGRAM FILES"

    %PROGRAMFILES(X86)% = "C:\PROGRAM FILES (X86)"

    These work as expected in a cmd window.

    BUT in Excel VBA, both variables point to the X86 directory

    environ("PROGRAMFILES") = "C:\PROGRAM FILES (X86)

    environ("PROGRAMFILES(X86)") = "C:\PROGRAM FILES (X86)

    I am running the 32bit version of Excel but in my code I want to shell to a 64-bit version of AutoCAD.

     

    Wednesday, August 06, 2014 7:32 PM
  • I have similar problem..

    Using Windows 7 Professional 64 bit with Excel 2013 Standard 32 bit

    In Windows there are two environment variables"

    %PROGRAMFILES% = "C:\PROGRAM FILES"

    %PROGRAMFILES(X86)% = "C:\PROGRAM FILES (X86)"

    These work as expected in a cmd window.

    BUT in Excel VBA, both variables point to the X86 directory

    environ("PROGRAMFILES") = "C:\PROGRAM FILES (X86)

    environ("PROGRAMFILES(X86)") = "C:\PROGRAM FILES (X86)

    I am running the 32bit version of Excel but in my code I want to shell to a 64-bit version of AutoCAD.

     

    That is correct.  The 32bit version points to the 32 bit environment.

    This is what it looks like under PowerShell 32 on WIn8 and WIn 7:

    ProgramFiles                   C:\Program Files (x86)
    ProgramFiles(x86)              C:\Program Files (x86)

    Under CMD shell:

    ProgramFiles=C:\Program Files (x86)
    ProgramFiles(x86)=C:\Program Files (x86)

    All values point only to the32 bit environment.  In the 64 bit environment the two point to the 32 (x86) and the 64 bit environments.

    The 64 bit locations are not usable in a 32 bit shell or program.

    This is by design.


    ¯\_(ツ)_/¯

    Wednesday, August 06, 2014 7:43 PM