[英]How to determine Windows Server 2016 version from registry
我有一個確定Windows Server版本的應用程序。 它從HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion
注冊表項讀取版本值。 它在Windows Server 2012,Windows Server 2012 R2上運行良好,並按預期返回6.2和6.3版本。 但是在Windows Server 2016上,即使我希望它是10.0,它仍然會返回6.3。 正確的注冊表項是否已移至其他位置? 我是否應該完全依賴此注冊表項? 這是Windows Server 2016的屏幕截圖:
我有使用Environment.OSVersion的另一種方法。 但是我不太喜歡它,因為它要求我在清單中明確指定兼容的Windows版本,這意味着將來需要進行更多的維護工作。
如上面的注釋中所述,存在CurrentMajorVersionNumber
, CurrentMinorVersionNumber
和CurrentBuildNumber
,它們都對應於Environment.OSVersion
將為您提供的值。
另一種方法是此頁面上描述的內容: https : //docs.microsoft.com/zh-cn/windows/desktop/SysInfo/getting-the-system-version
要獲取操作系統的完整版本號,請在系統DLL之一(例如Kernel32.dll)上調用GetFileVersionInfo函數。
在C#中看起來像這樣,並且應該在每個Windows版本上都可以使用:
var myFileVersionInfo = FileVersionInfo.GetVersionInfo(@"C:\Windows\System32\Kernel32.dll");
然后,您可以使用ProductVersion
屬性或ProductMajorPart
, ProductMinorPart
和ProductBuildPart
的組合。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.