1

I need to create a registry key pointing to a file located in the 32 Bit "Program Files" folder that works under both versions (i.e. x86 and x64) of Windows 7 (and higher), even if the accessing process is a 64Bit process in the x64 environment. This folder is:

C:\Program Files in 32Bit Windows
C:\Program Files (x86) in 64 Bit Windows

My problem currently is, that the %programfiles(x86)% variable is not set on 32 Bit windows. So I do not really know which unique variable I can use on both Windows systems to get to the 32 Bit Program Files folder. Any solution to this weird situation?

Erik
  • 2,316
  • 9
  • 36
  • 58
  • A possible duplicate of https://stackoverflow.com/questions/17688758/using-programfilesx86-on-windows-os-32bit – montonero Mar 06 '19 at 07:58
  • Similar, but not a duplicate. The post above is asking for existence of a specific variable, I search for a variable which is available on all systems, and always points to the ...(x86) directory. Maybe the original author had the same intention, but the question is definitely a different one! – Erik Mar 06 '19 at 12:12
  • Have you read accepted answer to that question? It's exactly about your question. – montonero Mar 06 '19 at 12:22
  • Have you read the last comment in the accepted question? The user clearly states what my problem is – Erik Mar 07 '19 at 08:30
  • Your question is about 32-bit Program Files folder. The variable `%ProgramFiles%` (for a 32-bit process) will point to `C:\Program Files (x86)` in 64-bit Windows and to `C:\Program Files` in 32-bit Windows. That's an answer to the question you have asked. If you want something other then please elaborate it. – montonero Mar 07 '19 at 08:43
  • The problem is that I want to start the 32Bit process from a 64Bit process, i.e. from Windows explorer reading a registry path for its right-click context menu. So I actually need a variable that will resolve to the 32Bit path on a 64Bit operating system pointing to a folder in the 32Bit Program Files folder, which will additionally also work on a 32 Bit system. I hope it has become a little bit clearer now. – Erik Mar 07 '19 at 09:09
  • My previous comment is exactly about your situation. Please read it again. A 32-bit process will always resolve `%ProgramFiles%` to a 32-bit Program Files folder. You could easily check it by running 32-bit `cmd.exe` on a 64-bit Windows and type `echo %ProgramFiles%` command there. Just in case: 32-bit `cmd.exe` on 64-bit Windows is located in `C:\Windows\SysWOW64` – montonero Mar 07 '19 at 09:16
  • No, please read my comment again: it is not about running a 32Bit process, but running a 64Bit process like Windows explorer, which is always 64 Bit in Windows x64. For example, you want to create a filetype extension for explorer in HKEY_CLASSES_ROOT \\ *, and point to your 32Bit application here by using an environment variable in the path name for the program to open with, the variable will resolve to the 64Bit path. It's NOT about running a 32Bit program from a 32Bit context in a 64 Bit system! I have edited the question accordingly – Erik Mar 07 '19 at 09:20
  • Your exact words: `The problem is that I want to start the 32Bit process from a 64Bit process`. Please answer a simple question: is your process a 32-bit? – montonero Mar 07 '19 at 09:28
  • The application to start is 32Bit, but the application that needs to resolve the path to find this application is 64 Bit. Windows Explorer Context Menu for example. – Erik Mar 07 '19 at 09:49
  • In such case you're out of luck. There's no universal variable for both 32- and 64-bit processes in both 32-bit and 64-bit Windows that will point to the 32-bit Program Files. For 64-bit Windows there's `%ProgramW6432%` – montonero Mar 07 '19 at 10:22
  • I think this is asking almost the same thing: https://superuser.com/questions/183437/how-to-write-the-path-of-a-32-bit-executable-in-the-windows-program-files-folde – StayOnTarget Apr 13 '21 at 17:47

0 Answers0