WNetGetUser

This is used to determine either the current default username, or the user identification used to establish a network connection.

DWORD WNetGetUser(
    LPTSTR lpName,
    LPTSTR lpUserID,
    LPDWORD lpBufferSize
    );
 
lpName
Contains the name of the local device the caller is interested in, or the name of a remote network resource that the user has made a connection to, or the name of a network provider, or NULL or the empty string if the caller is interested in the name of the user currently logged on to the system.
lpUserID
Points to a buffer to receive the user profile name. This is an identification string that the user made to establish the connection (for example, a user name, or group name).

If the name passed in is a network provider and the network does not have a network wide logon, then an empty string is returned.

If a network resource name is passed in, and the user is connected to that resource using different names, it is possible that a NP cannot resolve which user profile name to return. In this case the NP may make an arbitrary choice amongst the possible usernames.

lpBufferSize
WN_NOT_LOGGED_ON the user is not logged on to the system (lpName empty) or network (lpName a valid provider name).
WN_NOT_CONNECTED lpName not a redirected device nor a connected network name.
WN_NOT_SUPPORTED lpName is the name of a network that does not support network wide logon.
WN_MORE_DATA the buffer is too small
WN_FUNCTION_BUSY The MPR or NP is busy (possibly initializing). The caller should retry.
WN_NO_NETWORK network is not present.
WN_EXTENDED_ERROR a network specific error occurred. WNetGetLastError should be called to obtain a description of the error.