Search code examples
windows-8winjswindows-8.1

WinJS getPrincipalNameAsync


Some code to get the username of the logged in user on a Windows 8 store app:

var x = Windows.System.UserProfile.UserInformation;
var y = x.getPrincipalNameAsync().done(function(response) {
  console.log(response);
});

I have two VMs, Windows 8 and Windows 8.1. The code works on the solution on the Windows 8 VM, and today I followed this guide to re-target my application to Windows 8.1. And while the re-targeting worked and I can deploy the upgraded .appx to a 8.1 tablet, the code above just returns "".

Please help.


Solution

  • From the documentation:

    Only domain users have a principal name. Access to the principal name can be blocked by privacy settings (for example, if the UserInformation::NameAccessAllowed property is false). If access is blocked, this method returns an empty string.

    So maybe your user is nto a domain user or the privacy on your windows8 machine is different from the other one.

    To make sure your privacy settings allow for the principal name to be read check on your machine in settings-->change pc settings-->Privacy and turn on the needed privacy setting.

    This is the complete documentation: http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.userprofile.userinformation.getprincipalnameasync.aspx