You can find all the information from
System.Environment
:
System.OperatingSystem system = System.Environment.OSVersion;
All the version information, and the version information on service packs — all is contained in this stricture. Except one detail: it does not explicitly say if it is 32- or 64-bit. Probably this is because this matter is from the different field: CPU
instruction-set architecture.
One simple way to get and recognize this string:
System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
Another way to figure out if you are running 32-bit or 64-bit code is to find a size of
IntPtr
:
int bits = System.Runtime.InteropServices.Marshal.SizeOf(typeof(System.IntPtr)) * 8;
This call will return either 32 or 64. You should understand that is says nothing about real CPU architecture, it says only the architecture on which the code is currently running. You can set a 32-bit target architecture for the application, and it will run as 32-bit (x86) even on a 64-bit system, on top of WoW64.
Please see:
http://en.wikipedia.org/wiki/WoW64[
^].
See also on the instruction-set architectures:
http://en.wikipedia.org/wiki/Instruction_set_architecture[
^].
Supported targets by .NET:
http://en.wikipedia.org/wiki/X86[
^],
http://en.wikipedia.org/wiki/X86-64[
^],
http://en.wikipedia.org/wiki/Itanium[
^].
Note that Itanium (IA-64) and x86-I64 are incompatible, but both are compatible with 32-bit x86.
—SA