次のコードを使用して、win 8 アプリで OS を検出します (これは 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の両方でその方法をテストし、毎回OSを正しく認識しました。
これはhttp://attackpattern.com/2013/03/device-information-in-windows-8-store-apps/の JavaScript ポートであり、その方法を示してくれた @DamienG に感謝します。