WNetAddConnection3

This function is used to establish a connection to a network object The routine may optionally prompt the user for login or authentication.


DWORD WNetAddConnection3(
    HWND hwndOwner,
    LPNETRESOURCE lpNetResource,
    LPTSTR lpPassword,
    LPTSTR lpUserID,
    DWORD dwFlags
    );

hwndOwner

A handle to a window which should be the owner for any messages or dialogs the network provider might display. This is used if CONNECT_INTERACTIVE is set.

lpNetResource

Specifies the network resource to connect to. This structure is defined the section describing Enumeration APIs. The following fields must be set when making a connection, the others are ignored.

lpRemoteName

Specifies the network resource to connect to. This is limited to MAX_PATH.

lpLocalName

Pointer to a buffer that specifies the local device name that is 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) in which case a connection to the network resource is made without making a redirection.

lpProvider

Specifies the NP to connect to. If NULL or empty string, Windows will try each NP in turn. The caller should set lpProvider only if it knows for sure which network it wants. Otherwise, it is preferable to let Windows determine which NP the network name maps to. If this is non NULL, Windows will try the named NP and no other.

dwType

Specifies the type of resource to connect to. It must be RESOURCETYPE_DISK or RESOURCETYPE_PRINT if lpLocalName is not the empty string. It may also be RESOURCETYPE_ANY if lpLocalName is the empty string.


lpPassword

Specifies the password to be used in making the connection, normally the password associated with lpUserID. A NULL value or string may be passed in to not specify the password. If the password is invalid or not specified, then the function tries to use the current default password. If this fails and CONNECT_INTERACTIVE is set, the function posts an appropriate dialog asking the user to type/retype the password.

lpUserID

This specifies the identity of the user needed to make the connection. If NULL, a default will be applied. This is used when the user wishes to connect to a resource, but has a different user name or account assigned to him for that resource. This identification represents a security context, and is NP specific.

This user specific information is stored to be subsequently used in re-establishing the connection (using a non-default username or telephone number, for example).

dwFlags

Any combination of the following values:

CONNECT_TEMPORARY

The connection is being established for browsing purposes and can be released quickly.

CONNECT_INTERACTIVE

May have interaction with the user for authentication purposes.

CONNECT_PROMPT

Do no use any defaults for usernames or passwords without offering user the chance to supply an alternative. This flag is only valid if CONNECT_INTERACTIVE is set.

CONNECT_UPDATE_PROFILE

If the connection should be made persistent. If set, the connection is automatically restored every time the user starts up and logs on to the network. A connection is only made persistent if the connection was successful. This flag is only valid if lpLocalName specifies a local device to redirect.

CONNECT_UPDATE_RECENT

If the connection should be put in the recent connection list. If set, and the connection is successfully added, it will be put in the recent connection list. This flag should typically have the opposite value to CONNECT_TEMPORARY.


WN_CANCEL

the user cancelled the add connection attempt through some user interface.

WN_BAD_PROVIDER

lpProvider does not match any NP

WN_BAD_NETNAME

lpRemoteName is not acceptable to any NP

WN_BAD_LOCALNAME

lpLocalName is invalid.

WN_BAD_PASSWORD

bad password and CONNECT_INTERACTIVE is not set.

WN_NOT_AUTHENTICATED

the call failed because the connection requires additional authentication information (e.g., a username or a password), not provided by the caller or the user through a dialog.

WN_NOT_LOGGED_ON

a system logon needs to occur before a network connection can be added.

WN_ALREADY_CONNECTED

lpLocalName already connected 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.

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_NETWORK

network is not present

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.