Phillipe G on Mon, 12 Jan 2015 08:48:30
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 ?
Matt Small on Mon, 12 Jan 2015 12:49:02
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.
Phillipe G on Tue, 13 Jan 2015 09:20:28
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.
Matt Small on Tue, 13 Jan 2015 14:57:12
So chop the ".com" part off and continue on. Is there a reason this doesn't work?
Phillipe G on Wed, 14 Jan 2015 08:11:21
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.
Matt Small on Wed, 14 Jan 2015 15:00:16
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.