none
[UWP][C#]Get Current Username RRS feed

  • Question

  • Hi,

    I'm sure I'm missing something really obvious here, but I don't seem to be able to get hold of the username of the user running the application we're developing. In our non-UWP applications we pick this up from the Windows environment. We then pass this up to our service and repository layers to get hold of what in-house applications and options a user should have access to.

    Our applications are only for use inside the company, so we take the Windows username as being good enough proof of who is running the application.

    I've looked at the Windows.System.User.FindAllAsync() method but I believe that would return all users. Even using this method, I still can't find the username - the KnownUserProperties enum properties are either blank or not the actual username.

    I've also looked through the Windows.Security.Credentials namespace with no luck.

    How do I get the current user username?

    Cheers,

    Darran

    P.S. We also use the client machine name - I've not looked for that yet.

    Tuesday, October 13, 2015 10:08 AM

All replies

  • Hi ranrads,

    Welcome to the Developing Universal Windows apps forum!

    Please try to check the official UserInfo sample to see if it works for you. I have tested in my side, I can get the following result:

    Best Regards,
    Amy Peng

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, October 14, 2015 7:44 AM
    Owner
  • Hi Amy,

    Thanks for that. I'd been looking at the UserInfo sample. What I hadn't noticed was that I can get the username from the domainName property (I'd not checked the outcome of that because I assumed it was just the actual domain) by splitting string around the "\".

    I'm a little confused by the FindAllAsync() method used - why does this return a single user even when multiple users are logged onto the computer? It seems a little misleading.

    Many thanks,

    Darran

    Wednesday, October 14, 2015 9:48 AM
  • Hi ranrads,

    How can you enable multiple users to log on to your computer? I have two users in my computer and when I want to login with another user using remote desktop. It shows "Another user is signed in. If you continue , they will be disconnected." It seems that only one use can be logged on at one time in Windows 10. If you know how to enable multiple users to log on in Windows 10 please tell me.

    Thanks,

    Jay 

    Tuesday, October 20, 2015 7:56 AM
  • If you use SSO you can have multiple active identities in any one Windows session

    http://pauliom.wordpress.com

    Tuesday, October 20, 2015 9:46 AM
  • Hi Darran,

    Did you use the FindAllAsync(UserType, UserAuthenticationStatus) | findAllAsync(UserType, UserAuthenticationStatus) method with the query condition?

    And what is your OS version? Win10 or Windows Server 2016 Technical Preview?

    I will give a test tomorrow on my work station to see if this is a API issue or not.

    ===Update===

    I've test with my Win10 machine and yes it can only get one user, however I've consult our Windows experts, officially Desktop environment only allow one user to remote login, perhaps you may enable this feature by some methods, but it against the licensing agreement and also not suggested, we cannot make sure it will behavior as expected.

    I do not have a Server 2016 Technical Preview off hand so I cannot simply test for you, but I believe it should work as expected.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    • Edited by Jamles Hez Tuesday, October 27, 2015 2:15 AM
    Monday, October 26, 2015 12:18 PM
  • System.Environment.UserName should give you what you need

    Monday, October 26, 2015 1:40 PM
  • As mentioned above, System::Environment is not available in UWP.
    Tuesday, November 5, 2019 10:00 PM