tags:

views:

651

answers:

2

I'm using GetUserName Win32 API to get the user name of my computer, but I found the user name is different (uppercase vs. lowercase only) when using my VPN connection into work when I was at home. I’m wondering if the VPN client or other software could be affecting the username?

A: 

Not 100% sure, but I suspect that GetUserName will end up talking to the DC when you're connected to your domain network, whereas it will use the local answer otherwise

Paul Betts
+2  A: 

The GetUserName API states:

Retrieves the name of the user associated with the current thread.

Use the GetUserNameEx function to retrieve the user name in a specified format. Additional information is provided by the IADsADSystemInfo interface.

So it looks like that GetUserName uses IADsADSystemInfo to get it's information.

If you look at the IADsADSystemInfo interface you see it has the method:

get_UserName
Retrieves the Active Directory distinguished name of the current user, which is the logged-on user or the user impersonated by the calling thread.

So when your connected via VPN to a domain login you will most likely get Active Directory distinguished name of the current user and when you aren't, you most likely get the user name that you typed in (in whatever case you typed in) to log onto the computer with.

Shane Powell
The user name is worng using IADsADSystemInfo to get it's information. The return user name is like this "EN=WYG,OU=XXX Address Lists,DC=apac,DC=XXX,DC=crop".
Yigang Wu