The environment variable PROCESSOR_ARCHITECTURE
contains the address width of the process that is being executed, which does not necessarily apply to the operating system or processors. A quick way to see this is by running the following command ...
$Env:PROCESSOR_ARCHITECTURE
... in 32-bit and 64-bit PowerShell sessions and output comparison.
So, if GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
returns "AMD64"
, then you definitely have a 64-bit process, operating systems, and processors. If it returns "x86"
then you will definitely have a 32-bit process, although you still won’t know whether the 32-bit or 64-bit operating system and processors are.
If you are really after the width of the address of the operating system, then .NET 4 offers the Environment. Property Is64BitOperatingSystem . You can also use WMI for any version of .NET to read the OSArchitecture
property of the OSArchitecture
class :
static string GetOSArchitecture() { var query = new WqlObjectQuery("SELECT OSArchitecture FROM Win32_OperatingSystem"); using (var searcher = new ManagementObjectSearcher(query)) using (var results = searcher.Get()) using (var enumerator = results.GetEnumerator()) { enumerator.MoveNext(); return (string) enumerator.Current.GetPropertyValue("OSArchitecture"); } }
... although, unfortunately, the OSArchitecture
property OSArchitecture
exists in Windows Vista / Server 2008 and later.
For all versions of Windows since 2000, you can try p / call the GetSystemInfo () function and checking the wProcessorArchitecture
member of the wProcessorArchitecture
structure.
Bacon source share