The GetUserName API states:
Gets the username associated with the current thread.
Use the GetUserNameEx function to get the username in the specified format. Additional information provided by the IADsADSystemInfo interface.
So it seems that GetUserName is using IADsADSystemInfo to get the information.
If you look at the IADsADSystemInfo interface, you will see that it has a way:
get_UserName
Retrieves the active directory by the distinguished name of the current user, which is the registered user or the user personified by the calling stream.
Therefore, when you connect via VPN to the domain login, you will most likely get a different Active Directory name for the current user, and when not, you will most likely get the username that you entered (in any case, you entered in) to enter the computer using.
source share