简体   繁体   中英

ExpandEnvironmentStrings( … ) on a x64 bit windows is expanding %programfiles% to x86 path

I have an x86 application running on a x64 version of Windows 10.

In my app, I am using ExpandEnvironmentStrings( ... ) to expand a user given values.

But when the variable is %programfiles% it is expanded to C:\\Program Files (x86)

Do I need to do something special to get an x86 app to expand the program file variable properly?

NB : when I use %programfiles% directly in explorer, it expands properly to C:\\Program Files .

I am developing on Visual Studio 2015.

When a 32-bit application expands the environment variable reference %ProgramFiles% , it always gets the folder path which contains by default the program folders of 32-bit applications. But this environment variable reference expands to folder path which contains by default the program folders of 64-bit applications when expanded from a 64-bit process (such as Windows Explorer).

The environment variable reference %ProgramW6432% must be used to get the program files folder path for 64-bit applications by a 32-bit process.

This is documented by Microsoft at WOW64 Implementation Details .

It is possible to check this by yourself by opening a 64-bit and a 32-bit command prompt – type %SystemRoot%\\SysWoW64\\cmd.exe to open a 32-bit command prompt on a 64-bit system. Then execute in both command prompt windows the command set for a complete list of environment variables with their current values or just set prog for a list of environment variables starting case-insensitive with string prog in name and their values.

See also Wikipedia article with the predefined Windows Environment Variables .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM