Platform SDK: Windows Networking

WNetGetUser

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

DWORD WNetGetUser(
  LPCTSTR lpName,     // device or resource name
  LPTSTR lpUserName,  // name buffer
  LPDWORD lpnLength   // buffer size
);

Parameters

lpName
[in] Pointer to a constant null-terminated string that specifies either the name of a local device that has been redirected to a network resource, or the remote name of a network resource to which a connection has been made without redirecting a local device.

If this parameter is NULL, the system returns the name of the current user for the process.

lpUserName
[out] Pointer to a buffer that receives the null-terminated user name.
lpnLength
[in/out] Pointer to a variable that specifies the size, in characters, of the buffer pointed to by the lpUserName parameter. If the call fails because the buffer is not large enough, this variable contains the required buffer size.

Return Values

If the function succeeds, the return value is NO_ERROR.

If the function fails, the return value can be one of the following error codes.

Value Meaning
ERROR_NOT_CONNECTED The device specified by the lpName parameter is not a redirected device or a connected network name.
ERROR_MORE_DATA More entries are available with subsequent calls.
ERROR_NO_NETWORK The network is unavailable.
ERROR_EXTENDED_ERROR A network-specific error occurred. To obtain a description of the error, call the WNetGetLastError function.
ERROR_NO_NET_OR_BAD_PATH None of the providers recognize the local name as having a connection. However, the network is not available for at least one provider to whom the connection may belong.

Remarks

For a code sample that illustrates how to use the WNetGetUser function to retrieve the name of the user associated with a local device, see Retrieving the User Name.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Requires Windows 95 or later.
  Header: Declared in Winnetwk.h.
  Library: Use Mpr.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.

See Also

Windows Networking (WNet) Overview, Windows Networking Functions, WNetGetConnection