locked
Username

    Question

  • Hi all,

    I am building an enterprise application on WinRT, connecting to my local network. I need to get the username of the logged-in user, same as the one you get with WindowsIdentity.GetCurrent().Name on Windows. (for example MYDOMAIN\Joe.Something)

    I tried to use UserInformation.GetDomainNameAsync but I am getting "MYDOMAIN.COM\Joe.Somethin"g which is not exatly the same. Why ? and What shoul I call to get the same username ?

    Thanks..

    Monday, January 12, 2015 8:48 AM

Answers

  • I don't think you understand - this is the correct function. The function is returning the full correct domain name which it understands. Even though you can log into the machine using only the first part, the correct name is the FQDN, and in fact, will work in every case where you need the domain name.

    Even my own machine here at Microsoft is like that.  I log into my machine using subdomain\username, but the full correct name is subdomain.microsoft.com\username.

    You can safely split the domainname using the"." and just use the first part.  I don't think there's any other WinRT method which will return something different, and it's likely just an implementation difference.  However, if this is going to be a sideloaded app, you can use a brokered component to call the .NET function and get what you want, but honestly that's overkill. 

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by Phillipe G Thursday, January 15, 2015 11:15 AM
    Wednesday, January 14, 2015 3:00 PM
    Moderator

All replies

  • It appears that the GetDomainNameAsync is returning the fully-qualified domain name (FQDN) of the local domain. You should test to see if you are able to log into the domain using the FQDN\username just to be sure it's correct.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, January 12, 2015 12:49 PM
    Moderator
  • Usernames are stored in a common db, and other Winforms applications are using it. The username I am getting and comparing has to be the same as other applications.

    Tuesday, January 13, 2015 9:20 AM
  • So chop the ".com" part off and continue on. Is there a reason this doesn't work?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, January 13, 2015 2:57 PM
    Moderator
  • Well I would prefer to find the correct function that gives me the same information. I am not sure what I am going to get once deployed on hundreds of computers.

    Wednesday, January 14, 2015 8:11 AM
  • I don't think you understand - this is the correct function. The function is returning the full correct domain name which it understands. Even though you can log into the machine using only the first part, the correct name is the FQDN, and in fact, will work in every case where you need the domain name.

    Even my own machine here at Microsoft is like that.  I log into my machine using subdomain\username, but the full correct name is subdomain.microsoft.com\username.

    You can safely split the domainname using the"." and just use the first part.  I don't think there's any other WinRT method which will return something different, and it's likely just an implementation difference.  However, if this is going to be a sideloaded app, you can use a brokered component to call the .NET function and get what you want, but honestly that's overkill. 

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by Phillipe G Thursday, January 15, 2015 11:15 AM
    Wednesday, January 14, 2015 3:00 PM
    Moderator