2

Simple question - I got Windows 8 "Metro" app in Store and somehow this app is crashing on Windows 8.1 Preview. I want to publish updated Windows 8 app with fix for the Windows 8.1 behavior, basically disabling one app functionality if it's running on Windows 8.1, but keep it for Windows 8 users.
Because it's not yet possible to publish apps compiled for windows 8.1, I need to provide this fix within Windows 8 app.

So how to detect the Windows 8 version from within my app?

Martin Suchan
  • 10,600
  • 3
  • 36
  • 66
  • Might be helpful, http://stackoverflow.com/questions/16975386/could-i-know-if-my-app-is-running-on-windows-rt-with-c/16996176#16996176 – Farhan Ghumra Jul 25 '13 at 11:19
  • possible duplicate of [How can we check if the current OS is win8 or blue](http://stackoverflow.com/questions/17406850/how-can-we-check-if-the-current-os-is-win8-or-blue) – Hans Passant Jul 25 '13 at 12:47

1 Answers1

1

I use following code to detect OS in my win 8 app (although it's js app you should be able to easily translate it to c#) :

var ROOT_CONTAINER = "{00000000-0000-0000-FFFF-FFFFFFFFFFFF}";
var MANUFACTURER_KEY = "System.Devices.Manufacturer";
var ITEM_NAME_KEY = "System.ItemNameDisplay";
var MODEL_NAME_KEY = "System.Devices.ModelName";
var DEVICE_CLASS_KEY = "{A45C254E-DF1C-4EFD-8020-67D146A850E0},10";
var DEVICE_CLASS_KEY_NO_SEMICOLON = '{A45C254E-DF1C-4EFD-8020-67D146A850E0}10';
var PRIMARY_CATEGORY_KEY = "{78C34FC8-104A-4ACA-9EA4-524D52996E57},97";
var ROOT_CONTAINER_QUERY = "System.Devices.ContainerId:=\"" + ROOT_CONTAINER + "\"";
var HAL_DEVICE_CLASS = "4d36e966-e325-11ce-bfc1-08002be10318";
var DEVICE_DRIVER_VERSION_KEY = "{A8B865DD-2E3D-4094-AD97-E593A70C75D6},3";
var pnpObject = Windows.Devices.Enumeration.Pnp.PnpObject;
var displayProperties = Windows.Graphics.Display.DisplayProperties;
var applicationView = Windows.UI.ViewManagement.ApplicationView;
var appViewState = Windows.UI.ViewManagement.ApplicationViewState;

function getHalDevice(property) {
    var properties = [property, DEVICE_CLASS_KEY];

    return pnpObject.findAllAsync(Windows.Devices.Enumeration.Pnp.PnpObjectType.device, properties, ROOT_CONTAINER_QUERY).then(function(rootDevices) {

        for (var i = 0; i < rootDevices.length; i++) {
            var rootDevice = rootDevices[i];
            if (!rootDevice.properties) continue;
            if (rootDevice.properties[DEVICE_CLASS_KEY_NO_SEMICOLON] == HAL_DEVICE_CLASS) {
                return rootDevice;
            }
        }
    });
}

getHalDevice(DEVICE_DRIVER_VERSION_KEY).done(function (halDevice) {
    if (!halDevice || !halDevice.properties[DEVICE_DRIVER_VERSION_KEY]) {
        deviceInfo.os.name = 'unknown';
        return;
    }

    var halName = halDevice.properties[DEVICE_DRIVER_VERSION_KEY];
    deviceInfo.os.number = halName;
    if (halName.indexOf('6.2.') > -1) {
        deviceInfo.os.name = 'Windows 8';
        return;
    }
    if (halName.indexOf('6.3.') > -1) {
        deviceInfo.os.name = 'Windows 8.1';
        return;
    }

    deviceInfo.os.name = 'unknown';
    return;
});

I've tested that method both in Win 8 and Win 8.1 and correctly recoginized OS each time.

It's a javascript port of http://attackpattern.com/2013/03/device-information-in-windows-8-store-apps/ and big thanks for @DamienG for showing a way of doing that, as it's bit crazy.

T W
  • 6,267
  • 2
  • 26
  • 33
  • 1
    Nice how you kind of "missed" the 4 lines of copyright statement on Damien's page http://attackpattern.com/2013/03/device-information-in-windows-8-store-apps/ =/ – TheCodeJunkie Sep 10 '13 at 08:17
  • 1
    @TheCodeJunkie credits added, my bad. I didn't simply copied it from blog post here, it's a code I use in my app and it's a javascript port of Damien's code with some changes. – T W Sep 10 '13 at 08:43