Tuesday, February 23, 2010

Cle Cd Dawn Of War Soulstorm

Problem to set an environment variable using ProgramFiles (x86)

I do this quick post after a configuration problem in a cmd file in Windows 7 64 bit.

Windows 7 64 bit defines two environment variables and two directories :

  • ProgramFiles (x86) that points to C: \\ Program Files (x86): here are normally installed 32-bit programs.
  • ProgramFiles pointing to C: \\ Program Files named in the Explorer Program: This is the directory that contains the 64-bit programs.

This distinction should already exist in Vista 64 bit. It is visible only if the OS is 64 bits. On a 32-bit version, there are only ProgramFiles.

To determine whether OS is 32 or 64 bits, the environment variable PROCESSOR_ARCHITECTURE can be used: it takes the values:

  • for AMD64 64-bit x86
  • for the 32-bit

This variable exists in Windows XP and it takes well under a x86 32-bit environment.

applications that interest me use a cmd that positions the environment variables to its execution (a common mechanism for applications or NatStar NS-DK), the base directory of my application is under% ProgramFiles% 32-bit. When passing under 64 bits, the remaining a binary 32-bit binary, it installs under% ProgramFiles (x86)% so I tried to reset my variables environment for the case of 64 bits. I go through an environment variable local to cmd and temporary PRGROOT to avoid changing all definitions.

I started with:

if "% PROCESSOR_ARCHITECTURE%" == "AMD64" (SET
PRGROOT =% programfiles (x86)%
)
if "% PROCESSOR_ARCHITECTURE%" == "x86" (SET
PRGROOT =% programfiles%
)

And then bizarrely PRGROOT takes the value C: \\ Program Files (x86 without the closing parenthesis.

After many tests, I tried the syntax (note the use of quotes around the complete assignment)

if "% PROCESSOR_ARCHITECTURE%" == "AMD64" (SET
"PRGROOT =% programfiles (x86)%"
)
if "% PROCESSOR_ARCHITECTURE % "==" x86 "(
SET PRGROOT =% programfiles%
)

And then everything goes well I found my right parenthesis.

I hope this post will be useful to others. There seems a little bug in the case of IF: it replaces% programfiles (x86)% of its value then there is the assignment. It takes the right parenthesis at the end of the IF and not as part of the value it should affect. The quotation is forced to consider closing parenthesis as part of the assignment.

0 comments:

Post a Comment