This function allows the caller to redirect (connect) a local device to a network resource. If successful, the connection will be made persistent.
DWORD WNetAddConnection( LPTSTR lpRemoteName, LPTSTR lpPassword, LPTSTR lpLocalName );
lpRemoteName
Specifies the network resource to connect to. This is limited to MAX_PATH.
lpPassword
Specifies the password to be used in making the connection.
The NULL value or string may be passed in to indicate that the caller wants the network to use the best password(s) it has available (such as no password, a default password, or an internally cached password).
lpLocalName
This should contain the name of a local device to be redirected, such as "F:" or "LPT1". The string is treated in a case insensitive manner, and may be the empty string (or NULL) to indicate the connection to the network resource is to be made without a device redirection (i.e., deviceless connection).
ERROR_BAD_DEV_TYPE | The device type and the resource type do not match. |
WN_BAD_NETNAME | lpRemoteName is not acceptable to any NP |
WN_BAD_LOCALNAME | lpLocalName is invalid. |
WN_BAD_PASSWORD | invalid password, or the the connection requires additional authentication not provided by the caller (e.g., a username) |
WN_ALREADY_CONNECTED | lpLocalName is already connected to a network drive or is to a local drive that is already in use locally (e.g. is used for a hard drive or RAM drive). |
WN_ACCESS_DENIED | access denied (user may need to logon) |
WN_NO_NETWORK | network is not present |
WN_CANNOT_OPEN_PROFILE | Unable to open the user profile to process persistent connections. |
WN_BAD_PROFILE | The user profile is in an incorrect format. |
WN_FUNCTION_BUSY | The MPR or NP is busy (possibly initializing). The caller should retry. |
WN_NO_NET_OR_BAD_PATH | the operation could not be handled either because a network component is not started or the specified name could not be handled. |
WN_EXTENDED_ERROR | a network specific error occurred. WNetGetLastError should be called to obtain a description of the error. |