Could I know if my app is running on Windows RT wi

2019-01-15 05:00发布

I know that there is no way to get OS version in Windows Store app, please let me explain more.

My app is a Windows Store app programming with C#. Some features of my app is depend on another desktop app (maybe it's not a good design). As I know, a third-party desktop app can not install on Windows RT, so I just want to know if my app is running on Windows RT and forbid some features of my app on Windows RT. I don't want to use GetNativeSystemInfo(), because it's a win32 API, and if I use that API, my app can't compli with any cpu.

3条回答
爷、活的狠高调
2楼-- · 2019-01-15 05:21

I don't know if this is really possible or not, but you can achieve result with "Conditional compilation symbols". For example you can add ARM only for ARM build, and build 3 separate packages: ARM, x86 and x64. You can find a lot of articles about how to use it. This is one of them Visual Studio: Use Conditional Compilation to Control Runtime Settings for Different Deployment Scenarios.

So you just need to set up for your project for ARM configuration special symbol ARM (like in this screenshot you see LIVE).

enter image description here

After this you can use C# directives: #if, #else, #endif to hide some portion of your code for ARM build.

查看更多
乱世女痞
3楼-- · 2019-01-15 05:38

Yep. Here's how!

Task<ProcessorArchitecture> WhatProcessor()
{
    var t = new TaskCompletionSource<ProcessorArchitecture>();
    var w = new WebView();
    w.AllowedScriptNotifyUris = WebView.AnyScriptNotifyUri;
    w.NavigateToString("<html />");
    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;
}

Best of luck!

查看更多
Melony?
4楼-- · 2019-01-15 05:39

Since some features of your app depend on a desktop app (which might be installed or not) you need to handle the "not-installed" state even in the x86 version of your app anyway.

What I'd do is to disable all those features per default, and on each startup I'd check if the desktop app exists. Only if it exists, I'd enable the additional features.

查看更多
登录 后发表回答