简体   繁体   English

如何获得Windows版本-如“ Windows 10,版本1607”?

[英]How to get Windows Version - as in “Windows 10, version 1607”?

It seems that the word "version" in reference to Windows is used for different things. 似乎Windows中的“版本”一词用于不同的事物。 For example, the Windows 10 "Anniversary Update" is labeled "Version 1607" by Microsoft ( here for example). 例如,在Windows 10“周年更新”是由微软(标记为“1607版” 这里的例子)。 But if I try to get the "Version" (on a PC with the Anniversary Update installed) using the following code, nothing is returned that looks like "1607". 但是,如果我尝试使用以下代码获取“版本”(在安装了周年更新的PC上),则不会返回任何类似于“ 1607”的内容。

// Get Version details
Version ver = os.Version;
Console.WriteLine("Major version: " + ver.Major);
Console.WriteLine("Major Revision: " + ver.MajorRevision);
Console.WriteLine("Minor version: " + ver.Minor);
Console.WriteLine("Minor Revision: " + ver.MinorRevision);
Console.WriteLine("Build: " + ver.Build);

I get this: 我得到这个:

Major version: 6
Major Revision: 0
Minor version: 2
Minor Revision: 0
Build: 9200

How do I get the Windows 10 "version" as in "Version 1607"? 如何获得Windows 10“版本”,如“版本1607”?

Thanks! 谢谢!

according to MSDN official link there's a specific version number for each windows version out there. 根据MSDN官方链接 ,每个Windows版本都有一个特定的版本号。 in dot net this can be read using the Environment.OSVersion object. 在点网中,可以使用Environment.OSVersion对象读取。

Console.WriteLine("OSVersion: {0}", Environment.OSVersion);
//output: OSVersion: Microsoft Windows NT 6.2.9200.0

What you are looking for is called ReleaseID not a version of windows. 您在寻找什么叫做ReleaseID,而不是Windows版本。 this be can read from registry key: 这可以从注册表项中读取:

HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ReleaseId HKEY_LOCAL_MACHINE \\ SOFTWARE \\ Microsoft \\ Windows NT \\ CurrentVersion \\ ReleaseId

using Microsoft.Win32;

string releaseId = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ReleaseId", "").ToString();
Console.WriteLine(releaseId);
 private static ManagementObject GetMngObj(string className)
    {
        var wmi = new ManagementClass(className);

        foreach (var o in wmi.GetInstances())
        {
            var mo = (ManagementObject)o;
            if (mo != null) return mo;
        }

        return null;
    }

    public static string GetOsVer()
    {
        try
        {
            ManagementObject mo = GetMngObj("Win32_OperatingSystem");

            if (null == mo)
                return string.Empty;

            return mo["Version"] as string;
        }
        catch (Exception e)
        {
            return string.Empty;
        }
    }

How to Use: 如何使用:

Console.WriteLine(GetOsVer());

Result: 10.0.0.1299 结果:10.0.0.1299

string Version = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion", "ProductName", null);

提供类似“ Windows 10 Enterprise”的名称。

In addition to Scott's answer, you can also get the product name (ex. Windows 10 Pro) with this (*I take no credit as Scott is the one who mentioned the registry path + I'm reusing his code below): 除了Scott的答案外,您还可以使用以下方式获得产品名称(例如Windows 10 Pro)(*我不相信,因为Scott是提到注册表路径的人+我将在下面重用他的代码):

using Microsoft.Win32;

string ProductName = 
Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName", "").ToString();
Console.WriteLine(ProductName);

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

相关问题 如何从UWP获取Windows的用户友好版本名称,如“Windows 10 Pro” - How can I get User Friendly version name of Windows like 'Windows 10 Pro' from UWP 获取 Windows 中的当前版本操作系统 C# 中的 10 - Get current version OS in Windows 10 in C# 如何在 UWP 应用程序(C# 或 WinJS)中获取 Windows 10 版本(例如 1809、1903、1909...)? - How to get Windows 10 version (e.g. 1809, 1903, 1909, ...) in a UWP app (C# or WinJS)? 如何获取Windows版本以包含在UserAgent字符串中 - How to get the Windows version to include in a UserAgent string 如何在Windows Phone中获取应用程序版本? - How to get app version in Windows Phone? 如何在Windows Universal App中获取应用程序版本? - How to get app version in Windows Universal App? C#,如何为Windows版本(例如Windows 8或Windows 10)制作if循环语句? - C#, how make a if loop statement for windows version like windows 8 or windows 10? 在Windows中获取驱动程序文件版本 - Get driver file version in windows ASP.NET 核心 ILogger Memory Windows 10 (1607) / ZAEA2342289CE3AA9B340Z6 服务器泄漏 - ASP.NET Core ILogger Memory Leak on Windows 10 (1607) / Windows Server 2016 如何识别Windows操作系统版本? - How to recognize Windows OS version?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM