Reputation: 953
I've been using
LookupAccountName
using the returned value from
GetUserName
to retrieve the current logged on AD Domain Name.
This has been happily working for a while on a number of machines with a number of different NT based OS's
That is, until today, when instead of returning the logged in AD Domain, it returned the Computer Name as the domain.
Can anyone explain why this would happen less than 0.5% of the time?
Upvotes: 0
Views: 1047
Reputation: 953
If there is an account on the local computer with the same name as the Active Directory username then LookupAccountName
will return the local computer name (being the local Domain Name), rather than the required AD Domain name.
Instead I should use GetUserNameEx
with NameUserPrincipal
to return the current user's principal name, which can be fed into LookupAccountName
to return the logged in Domain.
Upvotes: 3