3

This is a question related to Get OS-Version in WinRT Metro App C# but not its duplicate.

Is there any option to detect from a Metro application whether there is the desktop feature available on the system? I understand that detection of the OS version is not supported and that is OK imo.

However my metro app needs to know whether there is a Desktop available on the system it is running on.

By Desktop I mean extendable desktop - desktop, where 3rd party desktop applications can be installed. As we know ARM based units will have the desktop too, but only with Microsoft built-in programs.

Can I distinguish whether my Metro app is running on a ARM based tablet with non-extendable desktop vs on all other (Intel based) devices with extendable desktop?

Community
  • 1
  • 1
Jan Zeman
  • 924
  • 10
  • 17

3 Answers3

3

After some more extensive search I found GetNativeSystemInfo method. The hint was right away on SO site - this question. This approach seems to be fully supported by Windows Store applications - the App Cert Kit test ran smoothly despite the fact that pinvoke was used.

I ended up with the following code:

    [DllImport("kernel32.dll")]
    internal static extern void GetNativeSystemInfo(ref SystemInfo lpSystemInfo);

    internal static bool IsArmBased()
    {
        var sysInfo = new SystemInfo();
        GetNativeSystemInfo(ref sysInfo);
        return sysInfo.wProcessorArchitecture == ProcessorArchitectureArm; //ushort 5
    }

This seems to be as a solution I was looking for. Please tell me if not or make me aware of whatever problems connected to such an approach. Thank you.

Community
  • 1
  • 1
Jan Zeman
  • 924
  • 10
  • 17
  • What happens to your app if, several releases from now, Microsoft decides to release a version of Windows RT for x86 processors (note: this is pure speculation - I have no idea if this is in the plans)? Using the processor architecture seems a poor way of figuring out if the OS you're on allows arbitrary desktop apps. – Larry Osterman Sep 06 '12 at 04:01
  • I will simply release new version too ;) But agree it surely is not an optimal solution. However if the philosophy behind says: Do not search for hardware, platform, OS, but search for features, then I would expect that in one of that future version there will be a simple API call to figure out the desktop capability... – Jan Zeman Sep 06 '12 at 13:44
  • Why? Jeff Brand asked this question above: What would you do differently if you knew you were running on a machine with the ability to run arbitrary desktop apps? – Larry Osterman Sep 07 '12 at 04:25
1

If this is HTML, you can use window.cpuClass to get if it's ARM, x86 or amd64.

A non dynamic version is to use target specific architectures rather than AnyCPU, and then use the flavours with #ifdefs to hard code it at build time. You have to submit 3 packages to the store, however.

Dominic Hopton
  • 7,262
  • 1
  • 22
  • 29
  • Oh, OK, the idea about 3 packages would be a solution. However what are the disadvantages of 3 different packages? More maintenance, maybe more confusion for the final users, and...? – Jan Zeman Sep 05 '12 at 16:21
  • 1
    No confusion for final users. They just install the app from the store and everything is seemless -- they don't know which package they get. For you, you've got 3 packages to upload, and depending on your test philosophy, 3 packages to test. – Dominic Hopton Sep 05 '12 at 16:22
0

Use a try {} catch(){} to access those libraries, if anything goes wrong assume the ARM version.