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?

4

1 回答 1

1

我使用以下代码在我的 win 8 应用程序中检测操作系统(虽然它是 js 应用程序,但您应该能够轻松地将其转换为 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;
});

我已经在 Win 8 和 Win 8.1 中测试过该方法,并且每次都能正确识别操作系统。

这是http://attackpattern.com/2013/03/device-information-in-windows-8-store-apps/的 javascript 端口,非常感谢@DamienG 展示了一种这样做的方式,因为它有点疯狂。

于 2013-07-30T18:33:38.303 回答