Page 1 of 1

How to return the x86 Program Files directory

Posted: Thu Dec 31, 2009 8:49 am
by Cyclops
This function will return the x86 Program Files directory in all 3 of the windows configurations

32 bit Windows
32 bit program running on 64 bit Windows
64 bit program running on 64 bit windows

Code: Select all


static string ProgramFilesx86()
{
    if( 8 == IntPtr.Size || (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))))
     {
         return Environment.GetEnvironmentVariable("ProgramFiles(x86)");
     }
     return Environment.GetEnvironmentVariable("ProgramFiles");
}