DWORD WNetAddConnection(lpszRemoteName, lpszPassword, lpszLocalName) | |||||
LPTSTR lpszRemoteName; | /* pointer to network device name | */ | |||
LPTSTR lpszPassword; | /* pointer to password | */ | |||
LPTSTR lpszLocalName; | /* pointer to local device name | */ |
The WNetAddConnection function allows the caller to redirect (connect) a local device to a network resource. A successful connection is persistent; that is, Windows automatically restores the connection during subsequent log-on operations.
lpszRemoteName
Points to a null-terminated string that specifies the network resource to connect to.
lpszPassword
Points to a null-terminated string that specifies the password to be used to make the connection. This is normally the password associated with the current user context.
If lpszPassword is NULL, the default password is used. If the string is empty, no password is used.
lpszLocalName
Points to a null-terminated string that specifies the name of a local device to be redirected, such as “F:” or “LPT1”. The string is not case sensitive. If the string is NULL, a connection to the network resource is made without making a redirection.
If the function is successful, the return value is NO_ERROR. Otherwise, it is an error code, which may be one of the following:
Value | Meaning |
ERROR_ACCESS_DENIED | Access is denied. |
ERROR_ALREADY_ASSIGNED | The device specified in lpszLocalName is already connected. |
ERROR_BAD_DEVICE | The value specified in lpszLocalName is invalid. |
ERROR_BAD_NET_NAME | The value specified in lpszRemoteName is not acceptable to any provider. |
ERROR_BAD_PROFILE | The user profile is in an incorrect format. |
ERROR_CANNOT_OPEN_PROFILE | The system is unable to open the user profile to process persistent connections. |
ERROR_DEVICE_ALREADY_REMEMBERED | An entry for the device specified in lpszLocalName is already in the user profile. |
ERROR_EXTENDED_ERROR | A network-specific error occurred. Use the WNetGetLastError function to obtain a description of the error. |
ERROR_INVALID_PASSWORD | The specified password is invalid. |
ERROR_NO_NET_OR_BAD_PATH | The operation could not be performed, either because a network component was not started or because the specified name could not be used. |
ERROR_NO_NETWORK | The network is not present. |
This function returns error codes for compatibility with Windows 3.1. For compatibility with Win32, the function also sets the error-code value returned by the GetLastError function.
WNetAddConnection2, WNetCancelConnection, WNetGetConnection