Windows 10 get DeviceFamilyVersion

后端 未结 4 1637
清酒与你
清酒与你 2020-12-06 07:51

I\'m working windows 10 10240 Univasal windows app, when i use Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamilyVersion to get deivce version, it return a string

相关标签:
4条回答
  • 2020-12-06 08:04

    Your application should treat the as opaque data and just log it "as is". It's a 64-bit decimal value as a string.

    Remember the intent of this API is to provide a log string from which you can reconstruct the OS version number for support/analytics. On your server-side analysis, you'd convert it if needed or just use it as a unique version identifier... If you are actually trying to parse it runtime, then you are using it incorrectly and quite likely to recreate same problems that resulted in GetVersionEx and VerifyVersionInfo being deprecated in the first place.

    Do not parse the string at runtime in your app. Just store "as is" Remember that with Windows 10, a customer really has no idea what you mean if you ask "What version of Windows do you have?". The answer is "10" and will likely still be "10" for a long time to come.

    0 讨论(0)
  • 2020-12-06 08:06

    The Windows 10 OS version value is located in this string property:
    Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamilyVersion

    It returns string value like "2814750438211613".
    To convert this long number to readable format use this:

    string sv = AnalyticsInfo.VersionInfo.DeviceFamilyVersion;
    ulong v = ulong.Parse(sv);
    ulong v1 = (v & 0xFFFF000000000000L) >> 48;
    ulong v2 = (v & 0x0000FFFF00000000L) >> 32;
    ulong v3 = (v & 0x00000000FFFF0000L) >> 16;
    ulong v4 = v & 0x000000000000FFFFL;
    string version = $"{v1}.{v2}.{v3}.{v4}"; // == 10.0.10240.16413
    
    0 讨论(0)
  • 2020-12-06 08:13

    Just a nifty way of doing this .. I Creadted a Enum that is used to match predefined device families

    public enum DeviceFamily
    {
        Unknown,
        Desktop,
        Tablet,
        Mobile,
        SurfaceHub,
        Xbox,
        Iot
    }
    

    This method will check and parse it into the enum.

       var q = ResourceContext.GetForCurrentView().QualifierValues;
        if (q.ContainsKey("DeviceFamily"))
        {
            try
            {
                Enum.Parse(typeof(DeviceFamily) , q["DeviceFamily"]);
                //send the user notification about the device family he is in.
            }
            catch (Exception ex) { }
        }
    
    0 讨论(0)
  • 2020-12-06 08:17

    If you found this question and like me you are looking for a way to do this in JavaScript, then you might find this useful.

    getDeviceFamilyVersion() {
        let deviceFamilyVersion = Windows.System.Profile.AnalyticsInfo.versionInfo.deviceFamilyVersion;
        let deviceFamilyVersionDecimalFormat = parseInt(deviceFamilyVersion);
    
        if (isNaN(deviceFamilyVersionDecimalFormat)) {
            throw new Error('cannot parse device family version number');
        }
    
        let hexString = deviceFamilyVersionDecimalFormat.toString(16).toUpperCase();
    
        while (hexString.length !== 16) { // this is needed because JavaScript trims the leading zeros when converting to hex string
            hexString = '0' + hexString;
        }
    
        let hexStringIterator = 0;
        let versionString = '';
        while (hexStringIterator < hexString.length) {
            let subHexString = hexString.substring(hexStringIterator, hexStringIterator + 4);
            let decimalValue = parseInt(subHexString, 16);
    
            versionString += decimalValue + '.';
            hexStringIterator += 4;
        }
    
        return versionString.substring(0, versionString.length - 1);
    }
    
    0 讨论(0)
提交回复
热议问题