NPAddConnection

This function is used to form a connection to a remote resource and optionally redirect (connect) a local device to the network resource. Note that if reference counted sessions are being used and this call is made requesting a user name when there is also a connection with a different user name, then the previous user name is preserved and WN_ALREADY_CONNECTED is returned, and the reference count is not incremented (the caller must make a decision as to whether the current user name on the resource is acceptable).

DWORD NPAddConnection(  
  HWND hwndOwner,
  LPNETRESOURCE lpNetResource,
  LPTSTR lpUserID,
  LPTSTR lpPassword,
  DWORD dwFlags,
  LPTSTR lpAccessName,
  LPDWORD lpBufferSize,
  LPDWORD lpResult
  );
 
hwndOwner
A handle to a window that should be the owner for any messages or dialog boxes. This is valid only if CONNECT_INTERACTIVE is set, and should be used only to produce dialog boxes needed for authentication.
lpNetResource
Specifies the network resource being connected to. This structure is defined in the section describing Enumeration SPIs. The following fields are set, and the others should be ignored.
lpRemoteName The name of the network resource. This is a fully qualified name either returned in a NETRESOURCE structure from an enumeration, or provided by the user (through an Open dialog box, for example). If this parameter is a pointer to an empty string, then authentication is required for the root of the network, and the provider must return WN_NOT_LOGGED_ON to allow MPR the opportunity to call WNetLogon and then retry the NPAddConnection call.
lpLocalName This specifies 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 a pointer to an empty string. In this case, a connection to the network resource is made without making a redirection.

dwType
Specifies the type of resource to connect to. It is RESOURCETYPE_DISK or RESOURCETYPE_PRINT if lpLocalName is not a NULL string. It may also be RESOURCETYPE_ANY if lpLocalName is a NULL pointer or string. On exit, this parameter is filled with a device type to indicate what type of device was connected.
lpUserID
This specifies the user identification used to make the connection. If NULL, the current authentication (currently logged on user) or any other defaults known to the NP should be applied. This is used when users wish to connect to a resource, but they have a different user name or account assigned to them for that resource. Whatever user identification is finally used is the lpUserID string returned from NPGetUserName after adding the connection. The NP implementation should consider keeping this information on the client to avoid generating unnecessary network traffic.
lpPassword
Specifies the password to be used in making the connection. The password is typically the one associated with lpUserProfileName. The NULL value may be passed in to indicate to the function to use the default password. An empty string may be used to indicate no password.
dwFlags
Any combination of the following values:
CONNECT_TEMPORARY The connection is being established for browsing purposes and will probably be released quickly.
CONNECT_REFCOUNT The connection is being made by an application that is able to delete the connection when it is done using it (by calling WNetCancelConnection2 with dwFlags set to the value of the CONNECT_RECOUNT bit returned in the lpResult field of this call). The application typically only does the deletion if a local device is redirected or lpResult returns with CONNECT_REFCOUNT set.
CONNECT_INTERACTIVE May have interaction with the user for authentication purposes.
CONNECT_PROMPT Do not use any defaults for user names or passwords without offering the user a chance to supply an alternative. This flag is valid only if CONNECT_INTERACTIVE is set.

lpAccessName
Points to a buffer to receive the name that can be used to make system requests on the connection. This conversion is useful for adding connections to aliased resources, such as through a directory service. If the provider does not support aliased connections, then lpAccessName and lpBufferSize may be ignored. If lpLocalName specifies a local device redirection, then lpAccessName is set to NULL by the caller.
lpBufferSize
This is used to specify the size of lpAccessName buffer passed in. If lpAccessName is NULL, then this field is ignored. If the call fails because the buffer is not big enough, this location is used to return the required buffer size and the connection should not be made.
lpResult
Pointer to a DWORD in which is returned additional information about the connection. This field is set to zero by the system before calling this function. Currently has the following bit value:
CONNECT_REFCOUNT The connection was made without using a local device redirection and is to a connection which can support reference counted sessions. If this bit is set, then calling NPCancelConnection will not interfere with other threads or processes that may be using the session and also called NPAddConnection themselves.

WN_BAD_NETNAME lpRemoteName in the lpNetResource structure is not acceptable to this provider.
WN_BAD_LOCALNAME lpLocalName in lpNetResource is invalid.
WN_ALREADY_CONNECTED lpLocalName is already connected or there is already a deviceless connection to the network resource with a different user name.
WN_NO_NETWORK The network is not present.
WN_NOT_LOGGED_ON The user is not logged on to the network.
WN_NOT_AUTHENTICATED The user is logged on, but is not authenticated to the part of the network containing the network resource.
WN_ACCESS_DENIED Access denied. The user is logged on and authenticated, but does not have the necessary permissions to access the resource.
WN_BAD_PASSWORD Invalid password and CONNECT_INTERACTIVE is not set.