求高手!.net 映射网络驱动器。WNetAddConnection2的用法。

如题所述

WNetAddConnection2 别名(alias):WNetAddConnection2A
WNetAddConnection2 库名(library):mpr
WNetAddConnection2 操作系统(os):Requires Windows NT 3.1 or later; Requires Windows 95 or later
WNetAddConnection2 参数表(parameter):
lpNetResource -- NETRESOURCE,在这个结构中设置了下述字段,对要连接的网络资源进行了定义:dwType,
lpLocalName (可为 vbNullString), lpRemoteName, lpProvider (设为 vbNullString
表示用默认提供者)。该结构的其他所有变量都会被忽略

lpPassword ----- String,可选的一个密码。如为vbNullString,表示采用当前用户的默认密码。如为一个空字串,则不用任何密码

lpUserName ----- String,用于连接的用户名。如为vbNullString,表示使用当前用户

dwFlags -------- Long,设为零;或指定常数CONNECT_UPDATE_PROFILE,表示创建永久性连接

?lpNetResource
Points to a NETRESOURCE structure that specifies details of the proposed connection: information about the network resource, the local device, and the network resource provider.
You must specify the following members of the NETRESOURCE structure:
dwType
Specifies the type of network resource to connect to. If lpLocalName points to a non-empty string, this member can be RESOURCETYPE_DISK or RESOURCETYPE_PRINT. If lpLocalName is NULL or points to an empty string, dwType can be RESOURCETYPE_DISK, RESOURCETYPE_PRINT, or RESOURCETYPE_ANY.
lpLocalName
Points to a null-terminated string that specifies the name of a local device to be redirected, such as 揊:?or 揕PT1? The string is treated in a case-insensitive manner. If the string is empty or lpLocalName is NULL, the function makes a connection to the network resource without redirecting a local device.
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抯 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 sure which network provider you want to use. Otherwise, let the operating system determine which 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 WNetAddConnection2 function ignores the other members of the NETRESOURCE structure.

?lpPassword
Points to a null-terminated string that specifies a password to be used in making the network connection.
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.

?lpUsername
Points to a null-terminated string that specifies a user name to be used in making the connection.
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.

?dwFlags
A set of bit flags that specify connection options. The following bit flag constant is currently defined:
CONNECT_UPDATE_PROFILE
The network resource connection should be remembered.

If this bit flag is set, the operating system automatically attempts to restore the connection when the user logs on.
The operating system remembers only successful connections that redirect local devices. It does not remember unsuccessful connections or 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.

WNetAddConnection2 返回值(return):

Long,零表示成功。会设置GetLastError。如GetLastError是ERROR_EXTENDED_ERROR,则可用WNetGetLastError取得额外的错误信息
If the function succeeds, the return value is NO_ERROR.

If the function fails, the return value is an error code. Returning an error code provides compatibility with the behavior of the Windows 3.1 function WNetAddConnection. You can also call the GetLastError function to obtain the (same) error code. One of the following error codes may be returned when WNetAddConnection2 fails:
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_DEV_TYPE
The type of local device and the type of network resource do not match.

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_PROFILE
The user profile is in an incorrect format.

ERROR_BAD_PROVIDER
The value specified by lpProvider does not match any provider.

ERROR_BUSY
The router or provider is busy, possibly initializing. The caller should retry.

ERROR_CANCELLED
The attempt to make the connection was cancelled by the user through a dialog box from one of the network resource providers, or by a called resource.

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 lpLocalName is already in the user profile.

ERROR_EXTENDED_ERROR
A network-specific error occured. Call the WNetGetLastError function to get a description of the error.

ERROR_INVALID_PASSWORD
The specified password is invalid.

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.
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网