Platform SDK: Windows Networking |
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 );
If this parameter is NULL, the system returns the name of the current user for the process.
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. |
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.
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.
Windows Networking (WNet) Overview, Windows Networking Functions, WNetGetConnection