Platform SDK: Network Management

NetUseAdd

The NetUseAdd function establishes a connection between the local computer and a remote server. You can specify a local drive letter or a printer device to connect. If you do not specify a local drive letter or printer device, the function authenticates the client with the server for future connections.

Win32-based applications can also use the WNetAddConnection2 and WNetAddConnection3 functions to redirect a local device to a network resource.

Security Requirements

No special group membership is required to call the NetUseAdd function. This function cannot be executed on a remote server.

NET_API_STATUS NetUseAdd (
  LPWSTR UncServerName,  
  DWORD Level,           
  LPBYTE Buf,            
  LPDWORD ParmError      
);

Parameters

UncServerName
[in] Reserved; must be NULL.
Level
[in] Specifies the information level of the data. This parameter can be one of the following values.
Value Meaning
1 Specifies information about the connection between a local device and a shared resource, including connection status and type. The Buf parameter is a pointer to a USE_INFO_1 structure.
2 Specifies information about the connection between a local device and a shared resource. Information includes the connection status and type, and a user name and domain name. The Buf parameter is a pointer to a USE_INFO_2 structure.

Buf
[in] Pointer to the buffer that specifies the data. The format of this data depends on the value of the Level parameter.
ParmError
[out] Pointer to a DWORD value that receives the index of the first member of the information structure in error when the ERROR_INVALID_PARAMETER error is returned. If this parameter is NULL, the index is not returned on error. For more information, see the following Remarks section.

Return Values

If the function succeeds, the return value is NERR_Success.

If the function fails, the return value is a Win32 API error code. For a list of error codes, see Error Codes.

Remarks

If the NetUseAdd function returns ERROR_INVALID_PARAMETER, you can use the ParmError parameter to indicate the first member of the information structure that is invalid. (The information structure begins with USE_INFO_ and its format is specified by the Level parameter.) The following table lists the values that can be returned in the ParmError parameter and the corresponding structure member that is in error. (The prefix ui*_ indicates that the member can begin with multiple prefixes, for example, ui1_ or ui2_.)

Value Member
USE_LOCAL_PARMNUM ui*_local
USE_REMOTE_PARMNUM ui*_remote
USE_PASSWORD_PARMNUM ui*_password
USE_ASGTYPE_PARMNUM ui*_asg_type
USE_USERNAME_PARMNUM ui*_username
USE_DOMAINNAME_PARMNUM ui*_domainname

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Unsupported.
  Header: Declared in Lmuse.h; include Lm.h.
  Library: Use Netapi32.lib.

See Also

Network Management Overview, Network Management Functions, Use Functions, USE_INFO_1, USE_INFO_2, NetUseDel, WNetAddConnection2, WNetAddConnection3