简体   繁体   English

如何从注册表中确定Windows Server 2016版本

[英]How to determine Windows Server 2016 version from registry

I have an application that determines Windows Server version. 我有一个确定Windows Server版本的应用程序。 It reads version value from HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion registry key. 它从HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion注册表项读取版本值。 It works well on Windows Server 2012, Windows Server 2012 R2 and returns 6.2 and 6.3 version as expected. 它在Windows Server 2012,Windows Server 2012 R2上运行良好,并按预期返回6.2和6.3版本。 However on Windows Server 2016 it still returns 6.3 even though I expected it to be 10.0. 但是在Windows Server 2016上,即使我希望它是10.0,它仍然会返回6.3。 Was the correct registry key moved to some different place? 正确的注册表项是否已移至其他位置? Should I rely on this registry entry at all? 我是否应该完全依赖此注册表项? Here is a screenshot from Windows Server 2016: 这是Windows Server 2016的屏幕截图:

在此处输入图片说明

I have an alternative way to use Environment.OSVersion. 我有使用Environment.OSVersion的另一种方法。 But I don't like it much because it requires me to specify explicitly in manifest the compatible windows versions and this means more maintenance work in the future. 但是我不太喜欢它,因为它要求我在清单中明确指定兼容的Windows版本,这意味着将来需要进行更多的维护工作。

As mentioned in the comments above, there are the CurrentMajorVersionNumber , CurrentMinorVersionNumber and CurrentBuildNumber , which all correspond to the values that Environment.OSVersion will give you. 如上面的注释中所述,存在CurrentMajorVersionNumberCurrentMinorVersionNumberCurrentBuildNumber ,它们都对应于Environment.OSVersion将为您提供的值。

Another way is what is described on this page: https://docs.microsoft.com/en-ca/windows/desktop/SysInfo/getting-the-system-version 另一种方法是此页面上描述的内容: https : //docs.microsoft.com/zh-cn/windows/desktop/SysInfo/getting-the-system-version

To obtain the full version number for the operating system, call the GetFileVersionInfo function on one of the system DLLs, such as Kernel32.dll 要获取操作系统的完整版本号,请在系统DLL之一(例如Kernel32.dll)上调用GetFileVersionInfo函数。

That would look something like this in C#, and should work on every Windows version: 在C#中看起来像这样,并且应该在每个Windows版本上都可以使用:

var myFileVersionInfo = FileVersionInfo.GetVersionInfo(@"C:\Windows\System32\Kernel32.dll");

Then you can use the ProductVersion property, or a combination of ProductMajorPart , ProductMinorPart and ProductBuildPart . 然后,您可以使用ProductVersion属性或ProductMajorPartProductMinorPartProductBuildPart的组合。

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

相关问题 如何确定Windows是哪个版本? - How to determine which version of Windows? 在Windows 8中的来宾帐户中如何确定Windows版本? - IN guest account in windows 8 how to determine the version of windows? 如何在不使用注册表的情况下确定Acrobat Reader版本 - How to determine Acrobat Reader version without using Registry 如何区分Windows的服务端版本和客户端版本? - How to distinguish the server version from the client version of Windows? 将Web应用程序从Windows Server 2008迁移到Windows Sever 2016 - Migrating Web Application from Windows Server 2008 to Windows Sever 2016 如何从注册表中检索已安装的应用程序版本? - How to retrieve installed app version from registry? 我如何从Windows服务器2016和.net .core 2.2上的Active Directory进行身份验证? - How would I authenticate from an Active Directory on a windows server 2016 and .net .core 2.2? 没有Registry确定框架版本的方法 - Way to determine framework version without Registry 如何在 Windows Server 2012 或 2016 中的默认 Edge 浏览器中从 .net C# 应用程序显示 PDF 命名目标? - How do I display a PDF Named Destination in Windows Server 2012 or 2016 in default Edge Browser from a .net C# app? 从ADO.NET确定SQL Server的版本 - Determine version of SQL Server from ADO.NET
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM