如何在我的Windows 8应用程序中检测到它在Windows 8.1上运行?

时间:2021-12-21 20:47:20

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.

简单的问题——我在商店里安装了Windows 8“Metro”应用程序,不知怎么的,这个应用程序在Windows 8.1的预览版上崩溃了。我想发布更新的Windows 8应用程序,以修复Windows 8.1的行为,如果它运行在Windows 8.1上,基本上可以禁用一个应用程序功能,但要为Windows 8用户保留它。因为目前还不可能发布为windows 8.1编写的应用程序,所以我需要在windows 8应用程序中提供这个补丁。

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

那么如何从我的应用程序中检测Windows 8版本呢?

1 个解决方案

#1


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#) :

我在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;
});

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

我在Win 8和Win 8.1中都测试过这种方法,每次都能正确地重新编码操作系统。

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.

它是一个javascript端口,http://attackpattern.com/2013/03/deinformation -in-window -8-store-apps/并对@DamienG表示感谢,因为它显示了一种方法,因为它有点疯狂。

#1


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#) :

我在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;
});

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

我在Win 8和Win 8.1中都测试过这种方法,每次都能正确地重新编码操作系统。

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.

它是一个javascript端口,http://attackpattern.com/2013/03/deinformation -in-window -8-store-apps/并对@DamienG表示感谢,因为它显示了一种方法,因为它有点疯狂。