WNetGetUser

  DWORD WNetGetUser(lpszLocalName, lpszUserName, lpcchBuffer)    
  LPTSTR lpszLocalName; /* pointer to local name to get user name for */
  LPTSTR lpszUserName; /* pointer to buffer for user name */
  LPDWORD lpcchBuffer; /* pointer to buffer size (in characters) */

The WNetGetUser function retrieves the current default user name or the user name used to establish a network connection.

Parameters

lpszLocalName

Points to a null-terminated string that specifies either the name of the local device to return the user name for, or a network name that the user has made a connection to.

If lpszLocalName is NULL, Windows returns the name of the current user for the process.

If lpszLocalName is a network name and the user is connected to that resource using different names, the provider may not be able to resolve which user name to return. In this case, the provider may make an arbitrary choice from the possible user names.

lpszUserName

Points to a buffer to receive the null-terminated user name.

lpcchBuffer

Specifies the size (in characters) of the buffer pointed to by the lpszUserName parameter. If the call fails because the buffer is not big enough, this location is used to return the required buffer size.

Return Value

If the function is successful, the return value is NO_ERROR. Otherwise, it is an error code, which may be one of the following:

Value Meaning

ERROR_NOT_CONNECTED The device specified by lpszLocalName is not a redirected device or a connected network name.
ERROR_MORE_DATA The buffer is too small.
ERROR_NO_NETWORK No network is present.
ERROR_EXTENDED_ERROR A network-specific error occurred. Use the WNetGetLastError function to obtain a description of the error.

This function returns error codes for compatibility with Windows 3.1. For compatibility with Win32, the function also sets the error-code value returned by the GetLastError function.

See Also

WNetGetConnection, WNetGetLastError