C# - How To Get Program Files (x86) On Windows 64 Bit


Answer :

The function below will return the x86 Program Files directory in all of these three Windows configurations:

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

 

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

If you're using .NET 4, there is a special folder enumeration ProgramFilesX86:

Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) 

Environment.GetEnvironmentVariable("PROGRAMFILES(X86)") ?? Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) 

Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?