获取C#中Windows 10的最新版本操作系统#
我使用C#。我试图让操作系统的最新版本:获取C#中Windows 10的最新版本操作系统#
OperatingSystem os = Environment.OSVersion;
Version ver = os.Version;
我上的Windows 10:6.2。
但6.2是的Windows 8或的WindowsServer 2012(Detect Windows version in .net)
我发现下面的解决方案(How can I detect if my app is running on Windows 10)。
static bool IsWindows10()
{
var reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
string productName = (string)reg.GetValue("ProductName");
return productName.StartsWith("Windows 10");
}
这是最好的方式获得在C#中的当前版本?
添加application manifest到您的应用程序,并添加Windows 8.1和Windows 10的supportedOS Id到清单:
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
</application>
</compatibility>
现在Environment.OSVersion
包括正确的数据对于Windows 8.1和Windows 10而不是6.2来表示您运行Windows 8.这是一个change since Windows 8.1。
谢谢,它的作品! – Olga
这是Microsoft官方链接,指示how to get the System Version。这实际上是对Version API Helper Functions
通话所以基本上必须将此代码转换成C#,因为它是在C++中,然后只保留在Windows 10的一部分...
#include <windows.h>
#include <stdio.h>
#include <VersionHelpers.h>
int
__cdecl
wmain(
__in int argc,
__in_ecount(argc) PCWSTR argv[]
)
{
UNREFERENCED_PARAMETER(argc);
UNREFERENCED_PARAMETER(argv);
if (IsWindows10OrGreater())
{
printf("Windows10OrGreater\n");
}
}
,如果你喜欢尝试阅读代码,你可以看看this one link。此DLL可以用来获取OS的信息...
也许检查在这一个:http://*.com/questions/6331826/get-os-version-friendly-name-in-c-sharp –
@olga你添加了清单+ supportedOS指导? – magicandre1981