简体   繁体   English

如何确定Windows是哪个版本?

[英]How to determine which version of Windows?

  1. How to determine which version of Windows?如何确定Windows是哪个版本? WinXP, Vista or 7 etc. WinXP、Vista 或 7 等。
  2. 32 or 64 bit? 32 位还是 64 位?

UPD: for.Net 2.0 - 3.5升级版:for.Net 2.0 - 3.5

You're looking for the Environment.OSVersion , Environment.Is64BitProcess , and Environment.Is64BitOperatingSystem properties.您正在寻找Environment.OSVersionEnvironment.Is64BitProcessEnvironment.Is64BitOperatingSystem属性。

Before.Net 4.0, you can check whether the process is 64-bit by checking whether IntPtr.Size is 8 , and you can check whether the OS is 64-bit using this code :在.Net 4.0之前,可以通过检查IntPtr.Size是否为8来检查进程是否为64位,可以使用以下代码检查操作系统是否为64位:

public static bool Is64BitProcess
{
    get { return IntPtr.Size == 8; }
}

public static bool Is64BitOperatingSystem
{
    get
    {
        // Clearly if this is a 64-bit process we must be on a 64-bit OS.
        if (Is64BitProcess)
            return true;
        // Ok, so we are a 32-bit process, but is the OS 64-bit?
        // If we are running under Wow64 than the OS is 64-bit.
        bool isWow64;
        return ModuleContainsFunction("kernel32.dll", "IsWow64Process") && IsWow64Process(GetCurrentProcess(), out isWow64) && isWow64;
    }
}

static bool ModuleContainsFunction(string moduleName, string methodName)
{
    IntPtr hModule = GetModuleHandle(moduleName);
    if (hModule != IntPtr.Zero)
        return GetProcAddress(hModule, methodName) != IntPtr.Zero;
    return false;
}

[DllImport("kernel32.dll", SetLastError=true)]
[return:MarshalAs(UnmanagedType.Bool)]
extern static bool IsWow64Process(IntPtr hProcess, [MarshalAs(UnmanagedType.Bool)] out bool isWow64);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError=true)]
extern static IntPtr GetCurrentProcess();
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
extern static IntPtr GetModuleHandle(string moduleName);
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError=true)]
extern static IntPtr GetProcAddress(IntPtr hModule, string methodName);

Take a look at Environment.OSVersion and Environment.Is64BitOperatingSystem看看Environment.OSVersionEnvironment.Is64BitOperatingSystem

You could do你可以做

System.OperatingSystem osInfo = System.Environment.OSVersion;

Have a look at this .看看这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM