You can also use P / Invoke to call GetNativeSystemInfo and get the SystemInfo structure.
Another solution looks like this:
isWow64 = false; if (System.Environment.OSVersion.Version.Major >= 5 && System.Environment.OSVersion.Version.Minor >= 1) { var processHandle = GetProcessHandle((uint) System.Diagnostics.Process.GetCurrentProcess().Id); bool retVal; if (!NativeMethods.IsWow64Process(processHandle, out retVal)) { throw (new Win32Exception()); } isWow64 = retVal; }
Alternative solution (but not recommended) :)
public bool Is64bitOS { get { return Environment.GetEnvironmentVariable("ProgramFiles(x86)") != null; } } public string ProgramFilesX86 { get { string programFiles = Environment.GetEnvironmentVariable("ProgramFiles(x86)"); if (programFiles == null) { programFiles = Environment.GetEnvironmentVariable( "ProgramFiles"); } return programFiles; } }
Konstantin tarkus
source share