Search code examples
environment-variablesnmake

How to access the ProgramFiles environment variable from nmake on x64 machines?


I try to get the path to the ProgramFiles environmental variable, that is supposed to expand to C:\Program Files (x86) on a x64 machine and to C:\Program Files on a x86 machine.

The problems is that in the nmake file if I do:

 all:
      echo $(PROGRAMFILES)

This will expand to C:\Program Files everytime and this is wrong.

Environment details from a x64 machine:

ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files

:: this one is special, if will return different results based on current process x86/x64
ProgramFiles=C:\Program Files (x86) or C:\Program Files
PROCESSOR_ARCHITECTURE=x86 or x64

Now the updated question is how to get the location of x86 program files inside nmake, in a way this will work on both x86 and x64 machines?


Solution

  • This expression seems to work on 64-bit Windows 7, with nmake running in both 32-bit and 64-bit:

    %%PROGRAMFILES(x86)%%
    

    e.g.

    LC = %%PROGRAMFILES(x86)%%\Microsoft SDKs\Windows\v7.0A\bin\lc.exe