我可以知道我的应用程序是否在带有C#的Windows RT上运行?

我知道在Windowsapp store应用中无法获得操作系统版本,请让我解释一下。

我的应用程序是使用C#编写的Windowsapp store应用程序。 我的应用程序的一些function取决于另一个桌面应用程序(也许它不是一个好的设计)。 据我所知,第三方桌面应用程序无法在Windows RT上安装,因此我只想知道我的应用程序是否在Windows RT上运行,并禁止在Windows RT上运行我的应用程序的某些function。 我不想使用GetNativeSystemInfo(),因为它是一个win32 API,如果我使用该API,我的应用程序无法使用任何CPU。

是的。 这是如何做!

Task WhatProcessor() { var t = new TaskCompletionSource(); var w = new WebView(); w.AllowedScriptNotifyUris = WebView.AnyScriptNotifyUri; w.NavigateToString(""); NotifyEventHandler h = null; h = (s, e) => { // http://blogs.msdn.com/b/ie/archive/2012/07/12/ie10-user-agent-string-update.aspx // IE10 on Windows RT: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; ARM; Trident/6.0;) // 32-bit IE10 on 64-bit Windows: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0) // 64-bit IE10 on 64-bit Windows: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0) // 32-bit IE10 on 32-bit Windows: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0) try { if (e.Value.Contains("ARM;")) t.SetResult(Windows.System.ProcessorArchitecture.Arm); else if (e.Value.Contains("WOW64;") || e.Value.Contains("Win64;") || e.Value.Contains("x64;")) t.SetResult(Windows.System.ProcessorArchitecture.X64); else t.SetResult(Windows.System.ProcessorArchitecture.X86); } catch (Exception ex) { t.SetException(ex); } finally { /* release */ w.ScriptNotify -= h; } }; w.ScriptNotify += h; w.InvokeScript("execScript", new[] { "window.external.notify(navigator.userAgent); " }); return t.Task; } 

祝你好运!

我不知道这是否真的可能,但你可以用“条件编译符号”来实现结果。 例如,您可以仅为ARM构建添加ARM ,并构建3个单独的软件包:ARM,x86和x64。 你可以找到很多关于如何使用它的文章。 这是其中之一Visual Studio: 使用条件编译来控制不同部署方案的运行时设置 。

所以你只需要为你的项目设置ARM配置特殊符号ARM (就像你在这个截图中看到LIVE )。

在此处输入图像描述

在此之后,您可以使用C#指令: #if,#else,#endif来隐藏ARM构建的部分代码。

由于您的应用程序的某些function取决于桌面应用程序(可能已安装或未安装),因此即使在您的应用程序的x86版本中也需要处理“未安装”状态。

我要做的是默认禁用所有这些function,并在每次启动时检查桌面应用程序是否存在。 只有它存在,我才会启用其他function。