The WNetUseConnection function makes a connection to a network resource. The function can redirect a local device to the network resource.
The WNetUseConnection function is similar to the WNetAddConnection3 function. The main difference is that WNetUseConnection can automatically select an unused local device to be redirected to the network resource.
Windows 95:
For Windows 95, the lpUserName and lpPassword
parameters are in reverse order from those in the Windows NT version as
follows:
DWORD WNetUseConnection(
HWND hwndOwner, | |
LPNETRESOURCE lpNetResource, | |
LPTSTR lpUserName, | |
LPTSTR lpPassword, | |
DWORD dwFlags, | |
LPTSTR lpAccessName, | |
LPDWORD lpBufferSize, | |
LPDWORD lpResult | |
); |
For Windows NT the parameter order is as follows:
DWORD WNetUseConnection(
HWND hwndOwner, | |
LPNETRESOURCE lpNetResource, | |
LPTSTR lpPassword, | |
LPTSTR lpUserName, | |
DWORD dwFlags, | |
LPTSTR lpAccessName, | |
LPDWORD lpBufferSize, | |
LPDWORD lpResult | |
); |
You must specify the following members of the NETRESOURCE structure:
Member |
Description |
dwType |
Specifies the type of resource to connect to. It is most efficient to use a specific resource type (such as RESOURCETYPE_DISK or RESOURCETYPE_PRINT). However, if lpLocalName is NULL or points to an empty string and CONNECT_REDIRECT is not set, dwType can be RESOURCETYPE_ANY. This method works only if the function does not automatically choose a device to redirect to the network resource. |
lpLocalName |
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 treated in a case-insensitive manner. If the string is empty or if lpLocalName is NULL, a connection to the network occurs without redirection. If CONNECT_REDIRECT is set or the network requires a redirected local device, the function chooses a local device to redirect and returns the name of the device in lpAccessName. |
lpRemoteName |
Points to a null-terminated string that specifies the network resource to connect to. The string can be up to MAX_PATH characters in length. The string must follow the network provider’s naming conventions. |
lpProvider |
Points to a null-terminated string that specifies the network provider to connect to. If lpProvider is NULL or points to an empty string, the operating system attempts to determine the correct provider by parsing the string pointed to by lpRemoteName. |
You should set this member only if you know for certain which network provider you want to use. Otherwise, let the operating system determine which network provider the network name maps to. | |
If this member is not NULL, the operating system attempts to make a connection only to the named network provider. |
The WNetUseConnection function ignores the other members of the NETRESOURCE
structure.
If lpPassword is NULL, the function uses the current default password associated with the user specified by lpUserName.
If lpPassword points to an empty string, the function does not use a password.
If the connection fails because of an invalid password and CONNECT_INTERACTIVE
is set, the function displays a dialog box asking the user to type the
password.
If lpUserName is NULL, the function uses the default user name. The user context for the process provides the default user name.
The lpUserName parameter is specified when users want to connect to a network resource for which they have been assigned a user name or account other than the default user name or account.
The user-name string represents a security context. It may be specific to a
network provider.
Value |
Meaning |
CONNECT_INTERACTIVE |
If this flag is set, the operating system may interact with the user for authentication purposes. |
CONNECT_PROMPT |
This flag instructs the system not to use any default settings for user names or passwords without offering the user the chance to supply an alternative. This flag is ignored unless CONNECT_INTERACTIVE is set. |
CONNECT_REDIRECT |
This flag forces the redirection of a local device when making the connection. If lpLocalName specifies a local device to redirect, this flag has no effect, because the operating system attempts to redirect the specified device anyway. Otherwise, if the operating system automatically chooses a local device, lpAccessName must point to a return buffer and dwType must not be RESOURCETYPE_ANY. If this flag is not set, a local device is automatically chosen for redirection only if the network requires a local device to be redirected. |
CONNECT_UPDATE_PROFILE |
This flag instructs the operating system to store the network resource connection. If this bit flag is set, the operating system automatically attempts to restore the connection when the user logs on. The system remembers only successful connections that redirect local devices. It does not remember unsuccessful connections and deviceless connections. A deviceless connection occurs when lpLocalName is NULL or points to an empty string. If this bit flag is clear, the operating system will not automatically restore the connection at logon. |
If lpLocalName specifies a local device, this buffer is optional, and
will have the local device name copied into it. If lpLocalName does not
specify a device and the network requires a local device redirection, or if
CONNECT_REDIRECT is set, this buffer is required and the name of the
redirected local device is returned here. Otherwise, the name copied into the
buffer is that of a remote resource. If specified, this buffer must be at
least as large as the string pointed to by the lpRemoteName parameter.
Value |
Meaning |
CONNECT_LOCALDRIVE |
If this flag is set, the connection was made using a local device redirection. If the lpAccessName parameter points to a buffer, the local device name is copied to the buffer. |
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is one of the following error codes.
Value |
Meaning |
ERROR_ACCESS_DENIED |
Access to the network resource was denied. |
ERROR_ALREADY_ASSIGNED |
The local device specified by lpLocalName is already connected to a network resource. |
ERROR_BAD_DEVICE |
The value specified by lpLocalName is invalid. |
ERROR_BAD_NET_NAME |
The value specified by lpRemoteName is not acceptable to any network resource provider. The resource name is invalid, or the named resource cannot be located. |
ERROR_BAD_PROVIDER |
The value specified by lpProvider does not match any provider. |
ERROR_CANCELLED |
The attempt to make the connection was canceled by the user through a dialog box from one of the network resource providers or by a called resource. |
ERROR_EXTENDED_ERROR |
A network-specific error occurred. To get a description of the error, call the WNetGetLastError function. |
ERROR_INVALID_ADDRESS |
The caller passed in a pointer to a buffer that could not be accessed. |
ERROR_INVALID_PARAMETER |
This error is a result of one of the following conditions:
|
ERROR_INVALID_PASSWORD |
The specified password is invalid and CONNECT_INTERACTIVE is not set. |
ERROR_MORE_DATA |
The lpAccessName buffer is too small. If a local device is redirected, the buffer needs to be large enough to contain the local device name. Otherwise, the buffer needs to be large enough to contain either the string pointed to by lpRemoteName or the name of the connectable resource whose alias is pointed to by lpRemoteName. If this status is returned, then no connection has been made. |
ERROR_NO_MORE_ITEMS |
The operating system cannot automatically choose a local redirection because all the valid local devices are in use. |
ERROR_NO_NET_OR_BAD_PATH |
A network component has not started, or the specified name could not be handled. |
ERROR_NO_NETWORK |
There is no network present. |
WNetAddConnection, WNetAddConnection2, WNetAddConnection3, WnetCancelConnection, WNetGetConnection, WNetGetLastError
file: /Techref/os/win/api/win32/func/src/f92_15.htm, 18KB, , updated: 2000/4/7 11:19, local time: 2024/11/5 00:39,
3.15.25.34:LOG IN ©2024 PLEASE DON'T RIP! THIS SITE CLOSES OCT 28, 2024 SO LONG AND THANKS FOR ALL THE FISH!
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://linistepper.com/techref/os/win/api/win32/func/src/f92_15.htm"> WNetUseConnection</A> |
Did you find what you needed? |