Essaye avec l'API WNetAddConnection2()
'
' Déclaration des fonctions de l'API Windows
'
' Pour créer une conenction à un lecteur réseau
Private 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
'
' Déclaration des constantes de l'API Windows
'
' Constantes de code erreur renvoyé par WNetAddConnection2() et WNetCancelConnection()
Private Const NO_ERROR As Long = 0
Private Const ERROR_ACCESS_DENIED As Long = 5&
Private Const ERROR_ALREADY_ASSIGNED As Long = 85&
Private Const ERROR_BAD_DEV_TYPE As Long = 66&
Private Const ERROR_BAD_DEVICE As Long = 1200&
Private Const ERROR_BAD_NET_NAME As Long = 67&
Private Const ERROR_BAD_PROFILE As Long = 1206&
Private Const ERROR_BAD_PROVIDER As Long = 1204&
Private Const ERROR_BUSY As Long = 170&
Private Const ERROR_CANCELLED As Long = 1223&
Private Const ERROR_CANNOT_OPEN_PROFILE As Long = 1205&
Private Const ERROR_DEVICE_ALREADY_REMEMBERED As Long = 1202&
Private Const ERROR_EXTENDED_ERROR As Long = 1208&
Private Const ERROR_INVALID_PASSWORD As Long = 86&
Private Const ERROR_NO_NET_OR_BAD_PATH As Long = 1203&
Private Const ERROR_NO_NETWORK As Long = 1222&
Private Const ERROR_DEVICE_IN_USE As Long = 2404&
Private Const ERROR_NOT_CONNECTED As Long = 2250&
Private Const ERROR_OPEN_FILES As Long = 2401&
' Constante de type de ressource (NetResource.dwType) pour l'appel à WNetAddConnection2()
Private Const RESOURCETYPE_ANY As Long = &H0&
Private Const RESOURCETYPE_DISK As Long = &H1&
Private Const RESOURCETYPE_PRINT As Long = &H2&
Private Const RESOURCETYPE_UNKNOWN As Long = &HFFFF&
'
' Déclaration des types de l'API Windows
'
' Type pour la connection d'une ressource réseau avec WNetAddConnection2()
Private Type NETRESOURCE
dwScope As Long
dwType As Long
dwDisplayType As Long
dwUsage As Long
lpLocalName As String
lpRemoteName As String
lpComment As String
lpProvider As String
End Type
' Connecte un lecteur LocalName (="LettreDeLecteur:") à une ressource réseau (="\\Serveur\Partage")
Private Function ConnectNetworkDrive(ByVal RemoteName As String, ByVal LocalName As String) As Long
Dim NR As NETRESOURCE, Ret As Long
With NR
.lpRemoteName = RemoteName
.lpLocalName = LocalName
.dwType = RESOURCETYPE_DISK
.lpProvider = vbNullString
End With
Ret = WNetAddConnection2(NR, vbNullString, vbNullString, 0)
ConnectNetworkDrive = Ret
End Function
Remplace les deux vbNullString dans l'appel de l'API par ton mot de passe (le 1er) et le nom d'utilsiateur (le 2eme)
Christophe R.