繁体   English   中英

在 WinRT、Windows8(10) 应用程序中获取 Windows 版本

[英]Get Windows version in WinRT, Windows8(10) application

这个问题很简单。

我正在使用 VB.Net 开发 Windows8.1(+10) 应用程序。

而且,我想检测操作系统版本是 8.1 还是 10。甚至不想知道 XP、7 和 8 等其他版本。

但是,不推荐使用Environment.OsVersion

无法访问 Windows8 APP 中的注册表(即使有可能也是政策),

无法生成自定义清单(阻止)文件来检索版本信息,

无法使用“Kernel32.dll”(策略问题)进行提取。

如何在 Windows8.1 或 Windows10 Store 应用程序中获取 Windows 版本?

谢谢。


附加:

  1. 我想检索Windows版本(无论是8.1还是10)
  2. 这对于操作 Live Tile 很重要。
  3. 不改变批评行为或评论中提到的东西。 Windows Metro 应用程序提供了稍微不同的方法来固定开始菜单中的磁贴,这在不知道 Windows 版本的情况下处理起来非常烦人。 无论如何,这不是主要话题。
  4. VB.Net 或 C# 代码将不胜感激。 这不是“给我工作代码”的事情。
  5. 这个问题不仅在我身上,在其他网站上也是持续的话题:

http://www.codeproject.com/Articles/678606/Part-Overcoming-Windows-s-deprecation-of-GetVe

http://www.vbforums.com/showthread.php?776481-Get-OS-version-Windows-8-1-does-not-detect

唯一的问题是该解决方案要么基于 C++,要么不适用于 Windows 8.1(metro 应用程序)。

谢谢。

您应该做的是检查新方法是否可用。 如果它们可用,请使用它们,无论操作系统版本如何。 例子:

if (Windows.Foundation.Metadata.ApiInformation.IsMethodPresent("Windows.UI.ViewManagement.ApplicationView", "TryEnterFullScreenMode"))
{
     Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TryEnterFullScreenMode();   
}

我没有找到任何其他方法来做到这一点,所以这是我的方法。 (它在 C# 中,但您可以轻松地将其转换为 Visual Basic)

以下属性IsWindows10检测 Windows 8.1 或 Windows Phone 8.1 应用程序是否在 Windows 10(包括 Windows 10 移动版)设备上运行。

 #region IsWindows10

    static bool? _isWindows10;
    public static bool IsWindows10 => (_isWindows10 ?? (_isWindows10 = getIsWindows10Sync())).Value;

    static bool getIsWindows10Sync()
    {
        bool hasWindows81Property = Windows.ApplicationModel.Package.Current.GetType().GetRuntimeProperties().Any(r => r.Name == "DisplayName");
        bool hasWindowsPhone81Property = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().GetType().GetRuntimeProperties().Any(r => r.Name == "RawPixelsPerViewPixel");

        bool isWindows10 = hasWindows81Property && hasWindowsPhone81Property;
        return isWindows10;
    }
 #endregion

它是如何工作的?

在 Windows 8.1 中, Package类具有 Windows Phone 8.1 没有的DisplayName属性。 在 Windows Phone 8.1 中, DisplayInformation类具有 Windows 8.1 没有的RawPixelsPerViewPixel属性。 Windows 10(包括移动版)具有这两个属性。 这就是我们如何检测应用程序正在运行的操作系统。

暂无
暂无

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

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