0

I am writing a program that requires to run in 32 bits mode. This program reads the registry for file path and some are written using Windows environment variables such as "%PROGRAMFILES%\MySoftware".

My problem is that when I use ExpandEnvironmentStrings() I am getting "C:\Program Files (x86)\MySoftware" because my executable is 32 bits but the path that I am looking for is "C:\Program Files\MySoftware".

Turning off Wow64 does not affect ExpandEnvironmentStrings().

My solution would be to code my own "ExpandEnvironmentStrings()" function but there is probably better solution.

Nifaal
  • 9
  • 1
  • Consider %ProgramW6432%. – Hans Passant Oct 05 '17 at 09:45
  • "%PROGRAMFILES%\MySoftware" is already on the registry. I did not put it there. But I guess I can write something that replaces %PROGRAMFILES% with %ProgramW6432% when I find it on the filename. – Nifaal Oct 05 '17 at 09:47
  • Well, find whomever put it there and tell them they did it wrong. They need to observe the registry redirector behavior. Or just fix it yourself if they don't answer the telephone. – Hans Passant Oct 05 '17 at 09:52
  • I am scanning the registry for startup commands and installed services. It can be anything... – Nifaal Oct 05 '17 at 10:05
  • 2
    Those registry keys are intended for the OS, it has no trouble with it since it is 64-bits. If you can't create a 64-bit program yourself then "don't do it" is the only logical advice of course. – Hans Passant Oct 05 '17 at 10:12
  • How about creating a 64-bit utility that writes the expanded value to its stdout as a UTF-8 or UTF-16LE string? I'd prefer this over using 64-bit CMD with `echo`, since I wouldn't trust CMD with arbitrary strings from the registry. – Eryk Sun Oct 05 '17 at 12:13
  • I think I will just write a routine to find and replace env variables within paths with their 64 bits equivalents. – Nifaal Oct 05 '17 at 12:24
  • @Nifaal: make sure you do that replacement only when reading paths from keys that are redirected in 32bit processes. You wouldn't want to do that replacement when reading from an actual 32bit key, where `%PROGRAMFILES%` really should be `Program Files (x86)` and not `Program Files`. – Remy Lebeau Oct 05 '17 at 19:18

1 Answers1

0

Starting with Windows 7 you have a %ProgramW6432% that always points to the 64bit folder.

See WOW64 implemenation details

xMRi
  • 14,982
  • 3
  • 26
  • 59