获取.net 2008中的操作系统类型? [英] Get the type of OS in .net 2008?

查看:80
本文介绍了获取.net 2008中的操作系统类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取操作系统的详细信息,究竟是Win XP,WIN 7,还是.net 2008中的32位或64位等?

How to get the details of OS, wehther it is win XP, WIn 7, whether 32 bit ot 64 bit, etc from .net 2008?

推荐答案

您可以从System.Environment:
找到所有信息.
You can find all the information from System.Environment:

System.OperatingSystem system = System.Environment.OSVersion;



所有版本信息以及Service Pack上的版本信息都包含在此限制中.除了一个细节:它没有明确说明它是32位还是64位.可能是因为这是来自不同领域的问题:CPU 指令集体系结构.

获取和识别此字符串的一种简单方法:



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")



确定运行的是32位还是64位代码的另一种方法是找到大小IntPtr:



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;



该调用将返回32或64.您应该了解,这与真实的CPU架构无关,仅表示当前正在运行代码的架构.您可以为应用程序设置32位目标体系结构,即使在64位系统上,它也可以在WoW64之上以32位(x86)运行.

请参阅:
http://en.wikipedia.org/wiki/WoW64 [ http://en.wikipedia.org/wiki/Instruction_set_architecture [ http://en.wikipedia.org/wiki/X86 [ http://en.wikipedia.org/wiki/X86-64 [ http://en.wikipedia.org/wiki/Itanium [



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


下面提供的函数将在所有3种Windows配置中返回x86程序文件目录.

32位Windows
在64位Windows上运行的32位程序
在64位Windows上运行的64位程序

Below provided 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

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

     return Environment.GetEnvironmentVariable("ProgramFiles");
}


请参阅此内容,可能会对您有所帮助
http://dnohr.dk/aspnet/how-to-detect- browser-operating-system-os-with-aspnet [ ^ ]
Refer this, might help you
http://dnohr.dk/aspnet/how-to-detect-browser-operating-system-os-with-aspnet[^]


这篇关于获取.net 2008中的操作系统类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆