Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function retrieves the user name used to establish a network connection.

Syntax

DWORD WNetGetUser( 
  LPCTSTR 
lpName, 
  LPTSTR 
lpUserName, 
  LPDWORD 
lpnLength 
); 

Parameters

lpName

[in] Long pointer to a null-terminated string that specifies either a local name that has been redirected to a network resource, or the remote name of a network resource to which a connection has been made without necessarily creating a local name

lpUserName

[out] Long pointer to a buffer that receives the null-terminated user name.

lpnLength

[in, out] Long pointer to a variable that specifies the size, in characters, of the buffer pointed to by lpUserName. If the call fails because the buffer is not big enough, this variable contains the required buffer size.

Return Value

ERROR_SUCCESS indicates success. An error value indicates failure. To get extended error information, call GetLastError. Possible GetLastErrorerror values are described in the following table.

Value Description

ERROR_NOT_CONNECTED

The resource name specified by lpNameis not a connected network resource.

ERROR_MORE_DATA

The supplied buffer is not large enough to hold the user name.

ERROR_NO_NETWORK

No network is present.

The function returns error values for compatibility with Windows-based desktop platforms. For compatibility with the Win32 API, the function also sets the error value returned by GetLastError.

Requirements

Header winnetwk.h
Library coredll.lib
Windows Embedded CE Windows CE 2.0 and later
Windows Mobile Windows Mobile Version 5.0 and later