简单的问题 - 我在商店中获得了Windows 8“Metro”应用程序,不知何故,这个应用程序在Windows 8.1预览版上崩溃了。我想发布更新的Windows 8应用程序,修复Windows 8.1的行为,基本上禁用一个应用程序功能,如果它在Windows 8.1上运行,但保留给Windows 8用户。
因为还不可能发布为Windows 8.1编译的应用程序,所以我需要在Windows 8应用程序中提供此修复程序。
那么如何从我的应用程序中检测Windows 8版本?
答案 0 :(得分: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提供了一种方法,因为它有点疯狂。