Ciao a tutti,
devo mappare un indirizzo utilizzando la prima lettera disponibile (parto dalla Z e cerco fino alla C).
Per ora utilizzo il seguente codice, e sembra funzionare.
codice:
sub MappaIndirizzo
Dim Lettera As String
Dim i As Integer
Const Max = 90
Const Min = 65
Set wshNetwork = CreateObject("Wscript.Network")
For i = Max To Min Step -1
Lettera = RestituisciLettera(i)
If Lettera <> "" Then
wshNetwork.MapNetworkDrive Lettera & ":", "\\xxx.xxx.x.xxx\xxxxxx_xxxxxx", 0, "xxxxxx_xxxxxx", "1234567890"
Exit Sub
End If
Next i
MsgBox "Nessuna lettera disponibile per mappare un nuovo indirizzo"
End
End Sub
Function RestituisciLettera(I As Integer) As String
Dim SO_Drive, Risultato
Set SO_Drive = CreateObject("Scripting.FileSystemObject")
On Error GoTo OK
Set Risultato = SO_Drive.getdrive(LCase(Chr(I)))
RestituisciLettera = ""
On Error GoTo 0
Exit Function
OK:
RestituisciLettera = Chr(I)
If Err <> 68 Then
MsgBox Err
End
End If
On Error GoTo 0
End Function
Il problema è quando su un pc è mappata una lettera, ma l'unità non è ancora connessa perchè l'utente non ha ancora digitato la password per accederci. Se sul pc è mappata un'unità con la lettera "Z" e l'utente non si è ancora connesso, col programma che ho fatto la "Z" risulta libera.
Potrei ovviare al problema creandomi una lista da dos col comando "net use", ma vorrei evitare e proseguire su questa strada. Come posso fare?
Grazie
Luciano