Windows 10 Settings

In Windows 10 the user must explicitly give permission to access the user information data. The first time it runs the application, Windows 10 privacy settings automatically prompt the message box, to confirm whether the application can read the user information or not.

user

Later at some point of time, ifthe user doesn't like the application accessing information, then he or she can disable it (go to settings -> Privacy -> Account -> select the application and disable,

application

Application Setting

Application must enable the User Account information in the Package.appxmanifest file, otherwise the application can’t access the user information.

Let us see a simple example of how to read user name and display account information.

Define the User Modal class,
  1. public class UniversalUserInfo: INotifyPropertyChanged
  2. {
  3. private string _userName;
  4. public string UserName
  5. {
  6. get
  7. {
  8. return _userName;
  9. }
  10. set
  11. {
  12. _userName = value;
  13. OnPropertyChanged(nameof(UserName));
  14. }
  15. }
  16. private BitmapImage _imgStream;
  17. publi BitmapImageImgStream
  18. {
  19. get
  20. {
  21. return _imgStream;
  22. }
  23. set
  24. {
  25. _imgStream = value;
  26. OnPropertyChanged(nameof(ImgStream));
  27. }
  28. }
  29. private string _userType;
  30. public string UserType
  31. {
  32. get
  33. {
  34. return _userType;
  35. }
  36. set
  37. {
  38. _userType = value;
  39. OnPropertyChanged(nameof(UserType));
  40. }
  41. }
  42. private string _authenticationStatus;
  43. public string AuthenticationStatus
  44. {
  45. get
  46. {
  47. return _authenticationStatus;
  48. }
  49. set
  50. {
  51. _authenticationStatus = value;
  52. OnPropertyChanged(nameof(AuthenticationStatus));
  53. }
  54. }
  55. public eventPropertyChangedEventHandlerPropertyChanged;
  56. protected virtual voidOnPropertyChanged(string propertyName = null)
  57. {
  58. PropertyChanged ? .Invoke(this, new PropertyChangedEventArgs(propertyName));
  59. }
  60. }
User class using to read the user information

User.FindAllAsync(); this function used to get all the user information and read each user's properties, such as name or picture name. Use the KnowUserProperties to get all user properties.

There are wo ways we can pass this KnowUserProperties -- single parameter passes or multiple properties

User.GetPropertyAsync() – returns single properties value

Ex: User.GetPropertyAsync(KnownUserProperties.AccountName);

User.GetPropertiesAsync passes the collection of properties and returns the collection of properties value

Ex:
  1. User.GetPropertiesAsync(newList < string > ()
  2. {
  3. KnownUserProperties.DisplayName,
  4. KnownUserProperties.DisplayName
  5. });
This article example uses the collection of the properties to get all the user information. The following function is used to prepare the collection of the Properties,

Properties

Read the picture information, call the GetPictureAsync function, and pass the size (Note: read the picture information it’s not under the KnownUserProperties).

User.GetPictureAsync(UserPictureSize.Size424x424);

And function return the IRandomAccessStreamReference to display to the GUI, and convert to the Bitmap image,

function

User AuthenticationStatus and UserType information are Enum types, the below function uses to convert the Enum to String,

String

Find Users () function to read the complete information and assign the UniversalUserInfo class,

class


Here's the output:

output

Find the complete source code.