0

According to the KNOWNFOLDERID documentation, it seems to be saying that a 32-bit app cannot retrieve the 64-bit C:\Program Files folder path.

I have a 32-bit app and need the known folder for C:\Program Files, not C:\Program Files (x86).

I have tried to disable WOW64 and this does not help.

Is there a solution to this?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • *"I have tried to disable WOW64"* - You cannot *"disable"* WoW64. If you run a 32-bit application on a 64-bit OS, it naturally must run in the emulation layer. What have you really tried? – IInspectable Feb 26 '17 at 22:38
  • 1
    @IInspectable probably tried to disable WOW64's file system redirector instead. – Remy Lebeau Feb 26 '17 at 22:51
  • you can get *ProgramFiles* folder by `GetEnvironmentVariable` [`ProgramW6432`](https://msdn.microsoft.com/en-us/library/windows/desktop/aa384274(v=vs.85).aspx) – RbMm Feb 26 '17 at 22:57

1 Answers1

0

You can use GetEnvironmentVariable() to read the %ProgramW6432% variable according to Microsoft article WOW64 Implementation Details:

Environment Variables

When a 32-bit process is created by a 64-bit process, or when a 64-bit process is created by a 32-bit process, WOW64 sets the environment variables for the created process as shown in the following table.


64-bit process

PROCESSOR_ARCHITECTURE=AMD64 or PROCESSOR_ARCHITECTURE=IA64

ProgramFiles=%ProgramFiles%

ProgramW6432=%ProgramFiles%

CommonProgramFiles=%CommonProgramFiles%

CommonProgramW6432=%CommonProgramFiles%

Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP:  The ProgramW6432 and CommonProgramW6432 environment variables were added starting with Windows 7 and Windows Server 2008 R2.


32-bit process

PROCESSOR_ARCHITECTURE=x86

PROCESSOR_ARCHITEW6432=%PROCESSOR_ARCHITECTURE%

ProgramFiles=%ProgramFiles(x86)%

ProgramW6432=%ProgramFiles%

CommonProgramFiles=%CommonProgramFiles(x86)%

CommonProgramW6432=%CommonProgramFiles%

So, %ProgramFiles% will point to either the 32-bit or 64-bit folder depending on the architecture of the calling app, but on a 64-bit OS %ProgramW6432% will always point to the 64-bit folder in both architectures.

Mofi
  • 46,139
  • 17
  • 80
  • 143
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770