函数名(function):WNetAddConnection2别名(alias):WNetAddConnection2A库名(library):mpr操作系统(os):Requires Windows NT 3.1 or later; Requires Windows 95 or later参数表(parameter):lpNetResource -- NETRESOURCE ?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 返回值(return): Long 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. 说明(description):The WNetAddConnection2 function makes a connection to a network resource. The function can redirect a local device to the network resource. 声明(declare):Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long 例程(example):Enum Resources AddConnection2 .net对应函数(dotnet): .net例程(dotnet example):
?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 返回值(return):
Long
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.
说明(description):The WNetAddConnection2 function makes a connection to a network resource. The function can redirect a local device to the network resource.
声明(declare):Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long 例程(example):Enum Resources
AddConnection2
.net对应函数(dotnet):
.net例程(dotnet example):
不大懂.
网络这一块也是皮毛.
你是做的winform编程吧
您发的东东,貌似没有看懂,
在WebService层那里发出的错,原先是网络共享文件夹里保存文件发生权限问题了,用了API函数后解决问题了,但是有些机器突然冒出了1327这个问题,我就头晕了,
网上查不到
GetLastError是函数?