如下几个函数可供使用:
DWORD WNetAddConnection(
LPTSTR lpRemoteName, // pointer to network device name
LPTSTR lpPassword, // pointer to password
LPTSTR lpLocalName // pointer to local device name
);
DWORD WNetAddConnection2(
LPNETRESOURCE lpNetResource, // points to structure that
// specifies connection details
LPCTSTR lpPassword, // points to password string
LPCTSTR lpUsername, // points to user name string
DWORD dwFlags // set of bit flags that specify
// connection options
);
DWORD WNetAddConnection3(
HWND hwndOwner, // handle to an owner window for
// network provider dialog boxes
LPNETRESOURCE lpNetResource, // pointer to structure that
// specifies connection details
LPTSTR lpPassword, // pointer to password string
LPTSTR lpUserName, // pointer to user name string
DWORD dwFlags // set of bit flags that specify
// connection options
);
前面的兄弟已经说得很明白了,补充一点。
switch (dwResult)
{
case ERROR_ACCESS_DENIED:
Msg = "Access to the network resource was denied." ;
break ;
case ERROR_ALREADY_ASSIGNED:
Msg = "The local device is already connecteded to a network resource." ;
break ;
case ERROR_BAD_DEV_TYPE:
Msg = "The type of local device and the type of network resource do not match." ;
break ;
case ERROR_BAD_DEVICE:
Msg = "The value specified by lpLocalName is invalid." ;
break ;
case ERROR_BAD_NET_NAME:
Msg = "The resource name is invalid, or the named resource cannot be located." ;
break ;
case ERROR_BAD_PROFILE:
Msg = "The user profile is in an incorrect format." ;
break ;
case ERROR_BAD_PROVIDER:
Msg = "The value specified by lpProvider does not match any provider." ;
break ;
case ERROR_BUSY:
Msg = "The value specified by lpProvider does not match any provider." ;
break ;
case ERROR_CANCELLED:
Msg = "The connection was cancelled by the user." ;
break ;
case ERROR_CANNOT_OPEN_PROFILE:
Msg = "The system is unable to open the user profile." ;
break ;
case ERROR_DEVICE_ALREADY_REMEMBERED:
Msg = "An entry for the device specified in lpLocalName is already in the user profile." ;
break ;
case ERROR_EXTENDED_ERROR:
Msg = "A network-specific error occured." ;
break ;
case ERROR_INVALID_PASSWORD:
Msg = "The password is invalid." ;
break ;
case ERROR_NO_NET_OR_BAD_PATH:
Msg = "A network component has not started." ;
break ;
case ERROR_NO_NETWORK:
Msg = "No network." ;
break ;
}