0

I have a Windows 8.1 app which is used as an LOB application.

The application get the domain user using to following line of code:

string user = await Windows.System.UserProfile.UserInformation.GetDomainNameAsync();

This all works fine and the app is deployed on numerous 8.1 tablets.

However, I have just upgraded my PC to windows 10 and that line of code now returns an empty string.

I've had a google and found this article: https://msdn.microsoft.com/library/windows/apps/windows.system.userprofile.userinformation.aspx

But it's advice is just upgrade the app to a windows 10 universal app or rollback to windows 8.1. That is not really a very good option as I have tablets everywhere running 8.1.

So do anybody know how to get round this problem? This basically means I can't develop a windows 8 app on my windows 10 PC.

Sun
  • 4,458
  • 14
  • 66
  • 108

1 Answers1

0

The UserInformation class does not exist anymore in Windows 10.

See this link: https://msdn.microsoft.com/library/windows/apps/windows.system.userprofile.userinformation.aspx

If you scroll down to remark you'll find that the UserInformation class is replaced by the User Class:

Windows 10:

Apps compiled for Windows 8 that use the UserInformation class no longer return user information when running on Windows 10. This is because in Windows 10, apps do not have access to user information without explicit user consent, unlike in Windows 8 where this permission is granted by default.

If you have a Windows 8 app that uses the UserInformation class, you should migrate your app to the Universal Windows Platform (UWP) and access the User class instead. Universal Windows Platform (UWP) apps that access user information are now expected to declare a new capability, uap:userAccountInformation, and call new APIs, Windows.System.User.FindAllAsync and User.GetPropertiesAsync, to get the data.

Users installing the app are prompted to allow access to their user information. If the user allows the app to access the information, the app appears listed in the Privacy page of the Windows 10 Settings UI (Settings > Privacy > Account info). This allows Windows 10 users to enable access to user information on a per-app basis.

so the short answer is NO it's not possible without changing your code.

What you could do is check the OS runtime and implement 2 ways of getting the user info. 1 for windows 8 and 1 for windows 1 (by doing this you also enable your app to be used on Windows 10 devices)

How can I detect if my app is running on Windows 10

If app is running Windows 10: use User class
Else: use UserInformation class.

To test how it works on Windows 8 on your Windows 10 device you could add a Windows 8 VM and test the app in there. (not perfect but at least it is something)

Community
  • 1
  • 1
GeertvdC
  • 2,758
  • 1
  • 22
  • 26
  • The link was in my question – Sun Feb 18 '16 at 12:16
  • but the link gives you the answer. the code will still compile but just not work on Windows 10 and will return nothing instead of user info. on Windows 8.1 the code will still return the correct user info. there is NO other way. – GeertvdC Feb 18 '16 at 12:18
  • so if your question is is there any other workaround the answer is: no – GeertvdC Feb 18 '16 at 12:25
  • Yeah, I'm aware the link gives me an answer. I was asking in hope that somebody clever out there had created a solution to get round this. I find this very poor from Microsoft that the answer is just to upgrade the app. That means I can't use 1 PC to develop Win 8 and Win 10 apps simultaneously. Seems silly to me! – Sun Feb 18 '16 at 12:29
  • Ok updated my answer a bit. You might wanna add a version check in your code for this specific statement and retrieve user information for windows 10 on a different way. (see link in answer). – GeertvdC Feb 18 '16 at 12:38