Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 10 get DeviceFamilyVersion

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 "2814750438211605" instead of a version format (major.minor.revision.build). Anyone can tell me what the string "2814750438211605" means?

like image 237
tao Avatar asked Aug 03 '15 09:08

tao


Video Answer


3 Answers

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
like image 184
Martin Suchan Avatar answered Oct 06 '22 05:10

Martin Suchan


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.

like image 32
Chuck Walbourn Avatar answered Oct 06 '22 06:10

Chuck Walbourn


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);
}
like image 24
David Bohunek Avatar answered Oct 06 '22 05:10

David Bohunek