Windows 8: Finding the details of the current system (including processor architecture) from Win8 app

Someone asked me today how to find the details  of what system/processor architecture the metro app is running on. Searching on the Internet initially did not provide much help, but some deep dive finally did yield some results:

  1. On StackOverflow, someone pointed out that the C function GetNativeSystemInfo would provide all that information. I cannot find a WinRT Javascript/C# projection for this. However, if you do decide to go along this route, you may have to submit architecture specific versions of your app to the store because of the C library dependency. If instead you decide to write your WinRT component in C# and use PInvoke to invoke the function, you can probably do a purely managed version.
  2. A blog post by iLiveDigitally points out a much simpler way of doing this. See the code sample below on how. This approach, I believe, will work only if you upload the architecture specific versions of your app to the store. Purely managed code and Javascript apps are by default architecture neutral, so you when uploading to the store, you will have to deselect the neutral architecture and upload three binaries for arm/x86 and x64. The store automatically downloads the right version of the app for your architecture on your device, so this should work.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    switch (Windows.ApplicationModel.Package.current.id.architecture) {
    case Windows.System.ProcessorArchitecture.arm:
    // do arm stuff here
    case Windows.System.ProcessorArchitecture.x86:
    // do x86 stuff here
    case Windows.System.ProcessorArchitecture.x64:
    // do x64 stuff here
    case Windows.System.ProcessorArchitecture.neutral:
    // do neutral stuff here
    }