I am developing an app that is Windows universal 8.1 app. I want to get os version. before Windows 10 Mobile i could suppose that version is 8.1 but currently this assumption this is not true. is there a way for get os version in a Windows 8.1 Universal app?
Asked
Active
Viewed 799 times
1
-
@cFrozenDeath i see that. but is there a way to find out that device is 8.1 or 10? – Soheil Ghahremani Nov 29 '15 at 13:55
-
Of course, they run different .NET versions. If you build the app for 8.1 then it can run in 8.1 and 10; but if you build it for 10 it won't run in 8.1. Take into account that you cannot know if it's 8.1 or 10 if you build for 8.1 – Camilo Terevinto Nov 29 '15 at 13:58
-
@cFrozenDeath it is very strange for me why Microsoft doesn't exposed such Api to developers. then how AdDuplex knows OS Version(i think they have sdk for windows universal)? – Soheil Ghahremani Nov 29 '15 at 14:05
-
2I think Microsoft wants you to check for for specific features and not to rely on OS version. – ForguesR Nov 29 '15 at 14:08
-
@ForguesR i need version because my app send version to server for statistical purpose – Soheil Ghahremani Nov 29 '15 at 14:11
-
I have been looking over Google and MSDN, I couldn't find absolutely no API to check this. Do as @ForguesR says and decide the platform based on a W10-only feature. – Camilo Terevinto Nov 29 '15 at 14:12
-
You might consider [this](http://stackoverflow.com/a/15792337/1980659) but it looks like a lot of work. – ForguesR Nov 29 '15 at 14:16
-
I would think any analytics framework you use in your app would get the os version for you – Ken Tucker Nov 29 '15 at 15:39
1 Answers
3
Windows Phone 8.1 Silverlight apps can use the .NET version APIs. There is no supported mechanism to get a version number in Universal 8.1 apps, but you can try using reflection to get the Windows 10 AnalyticsInfo
class, which will at least tell you the version number if you are running on Windows 10.
Note: Checking the OS version is almost always the wrong thing to do, unless you're simply displaying it to the user (eg, in an "About" box) or sending it to your back-end analytics server for number crunching. It should not be used to make any run-time decisions, because in general it's a poor proxy for whatever-you're-actually-trying-to-do.
Here is a sample:
var analyticsInfoType = Type.GetType(
"Windows.System.Profile.AnalyticsInfo, Windows, ContentType=WindowsRuntime");
var versionInfoType = Type.GetType(
"Windows.System.Profile.AnalyticsVersionInfo, Windows, ContentType=WindowsRuntime");
if (analyticsInfoType == null || versionInfoType == null)
{
Debug.WriteLine("Apparently you are not on Windows 10");
return;
}
var versionInfoProperty = analyticsInfoType.GetRuntimeProperty("VersionInfo");
object versionInfo = versionInfoProperty.GetValue(null);
var versionProperty = versionInfoType.GetRuntimeProperty("DeviceFamilyVersion");
object familyVersion = versionProperty.GetValue(versionInfo);
long versionBytes;
if (!long.TryParse(familyVersion.ToString(), out versionBytes))
{
Debug.WriteLine("Can't parse version number");
return;
}
Version uapVersion = new Version((ushort)(versionBytes >> 48),
(ushort)(versionBytes >> 32),
(ushort)(versionBytes >> 16),
(ushort)(versionBytes));
Debug.WriteLine("UAP Version is " + uapVersion);

Peter Torr - MSFT
- 11,824
- 3
- 18
- 51