0

Possible Duplicate:
How to detect Windows 64 bit platform with .net?

Project : C# .5

Description: The code checks whether the underlying machine is 64 bit or 32 bit OS. Return Value: The code always return a null value. WHY ?

  if (8 == IntPtr.Size || (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))))
            {
                return Environment.GetEnvironmentVariable("SysWOW64");
            }
            return Environment.GetEnvironmentVariable("system32");
Community
  • 1
  • 1
Rauf
  • 12,326
  • 20
  • 77
  • 126
  • Is there any reason why you can't use `Environment.Is64BitOperatingSystem` or `Environment.Is64BitProcess`? – LukeH Sep 16 '11 at 10:19

2 Answers2

2

The code returns null because the variable that it is returning isn't set. Better way to check if you're on a 64 bit environment is to call Environment.Is64BitOperatingSystem and Environment.Is64BitProcess

Muhammad Hasan Khan
  • 34,648
  • 16
  • 88
  • 131
0
if (Environment.Is64BitOperatingSystem) 
{
    return Environment.GetEnvironmentVariable("SysWOW64"); 
}
else
{
    return Environment.GetEnvironmentVariable("system32");       
}
sloth
  • 99,095
  • 21
  • 171
  • 219
62071072SP
  • 1,963
  • 2
  • 19
  • 38