Parsing of %ProgramFiles% under 64-bit Windows

Things you’d like to miss in the future...
Forum rules
:warnred20: :warnred20: :warnred20: :warnred20: :warnred20: READ THIS AND DO IT!!! :warnred20: :warnred20: :warnred20: :warnred20: :warnred20:

:info: Please include the following information:
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).

:info: We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.

:info: When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".

:warnred20: :warnred20: :warnred20: :warnred20: :warnred20: READ THIS AND DO IT!!! :warnred20: :warnred20: :warnred20: :warnred20: :warnred20:
Post Reply
nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Parsing of %ProgramFiles% under 64-bit Windows

Post by nas8e9 »

I'm not entirely sure if this is a bug or a feature request, but here goes: when parsing %ProgramFiles% under 64-bit Windows, XYplorer returns the value of %ProgramFiles(x86)% instead of %ProgramFiles%. Under 64-bit Windows, 32-bit apps get installed in %ProgramFiles(x86)% and 64-bit apps get installed in %ProgramFiles%. When calling a 64-bit program (installed in %ProgramFiles%) from a script, using %ProgramFiles% doesn't work because it returns %ProgramFiles(x86)%.

By way of an example, when calling TeraCopy.exe installed in C:\Program Files\TeraCopy (i.e. %ProgramFiles%\TeraCopy), calling %ProgramFiles%\TeraCopy\TeraCopy.exe returns C:\Program Files (x86)\TeraCopy\TeraCopy.exe which is incorrect. I suspect this has to do with 64-bit Windows "lying" to a 32-bit app like XYplorer; also, the problem can be easily circumvented by hardcoding C:\Program Files\ instead of %ProgramFiles% since Vista and Windows 7 always assign C: to the Windows partition. Nevertheless, with 64-bit Windows and apps becoming more prevalent, it's an issue that may crop up more often.

OS: Windows 7 x64 RTM
XYplorer 8.40.0112 beta.

mwb1100
Posts: 213
Joined: 19 May 2007 06:20

Re: Parsing of %ProgramFiles% under 64-bit Windows

Post by mwb1100 »

By default on a 64-bit windows systems the following 'program files' related environment variables are set (I imagine a registry setting or something can change this):
  • %ProgramFiles%: for 32-bit processes is set to "C:\Program Files (x86)", for 64-bit processes is set to "C:\Program Files"
  • %ProgramFiles(x86)%: set to "C:\Program Files (x86)"
  • %ProgramW6432%: set to "C:\Program Files"
(Note the above directory names are localized)


XY is a 32-bit program, so the %ProgramFiles% variable points to the "C:\Program Files (x86)" directory. I'm not sure if XY can do anything reasonable here to solve your problem, because some programs are in the C:\Program Files" directory and others are in "C:\Program Files (x86)". It might be best to have the shortcut or script use the %ProgramW6432% environment variable for programs in "C:\Program Files".

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: Parsing of %ProgramFiles% under 64-bit Windows

Post by nas8e9 »

mwb1100 wrote:By default on a 64-bit windows systems the following 'program files' related environment variables are set (I imagine a registry setting or something can change this):
  • %ProgramFiles%: for 32-bit processes is set to "C:\Program Files (x86)", for 64-bit processes is set to "C:\Program Files"
  • %ProgramFiles(x86)%: set to "C:\Program Files (x86)"
  • %ProgramW6432%: set to "C:\Program Files"
(Note the above directory names are localized)


XY is a 32-bit program, so the %ProgramFiles% variable points to the "C:\Program Files (x86)" directory. I'm not sure if XY can do anything reasonable here to solve your problem, because some programs are in the C:\Program Files" directory and others are in "C:\Program Files (x86)". It might be best to have the shortcut or script use the %ProgramW6432% environment variable for programs in "C:\Program Files".
My main concern was whether this was something in XYplorer or a peculiarity of 64-bit Windows. There are indeed workarounds possible in scripting; thank you for confirming that this is a Windows thing.

Post Reply