Running a 64-bit executable from a 32-bit Windows application

What is the “correct” way for a 32-bit application to find the “Program Files” folder on 64-bit Windows? For example, I am running a 32-bit application with the VBScript engine and want to run 64-bit Excel (using ShellExec or similar). In a 32-bit world, I would check the "ProgramFiles" environment variable to get the base folder. I understand that as a 32-bit application on 64-bit Windows, this environment variable will point to the 32-bit program files folder - for example: C: \ Program Files (x86). But my 64-bit Excel will be under C: \ Program Files.

I want to avoid hard-coding a link to "c: \ program files".

+4
source share
2 answers

You can check the environment variable "ProgramW6432". It must exist and point to Program Files without x86 when running a 32-bit application on 64-bit Windows.

Documentation: MSDN

+4
source

Depending on the version of the window, you should use well-known apis folders.

http://msdn.microsoft.com/en-us/library/bb776911%28v=VS.85%29.aspx

In particular, you can use FOLDERID_ProgramFilesX64 in combination with SHGetKnownFolderPath .

+3
source

Source: https://habr.com/ru/post/1311872/


All Articles