views:

187

answers:

1

So, I have a 32 bit program which needs to check if files exist. However, the locations (which can come from both shortcuts and the registry) often make use of Environment Strings. I use the ExpandEnvironmentStrings api to expand them, then check if the file exists. However, because it is a 32-bit application (note environmental strings emulation), the paths are expanded to the wrong locations in some cases. As I don't know if paths I'm given are 32 bit or 64 bit, one simple solution is to just expand the relevant environmental strings (ProgramFiles and CommonProgramFiles) using both the 64bit locations and the 32bit locations manually. However, this feels a bit hacky. Is there a better way?

+2  A: 

Perhaps File System Redirector will be helpful. In particular see Wow64DisableWow64FsRedirection Function and its close friends described there.

Even so you'll probably need to do some checks to determine which strings you need to expand and whether you want the 32 or 64-bit expansion. For that I suspect a simple table of strings won't help. As you say %ProgramFiles% might mean the 32-bit path in some cases and the 64-bit path in others.

Bob Riemersma
The documentation says nothing (that I saw) about this impacting environmental strings. I tested them anyways, but they did not work.
Brian
This is useful for checking if files exist when those files are in the system32 directory, though I think one can avoid it by replacing "system" with "sysnative" when checking for existence.
Brian