Voici un script qui permet de connecter un lecteur avec authentification en fonction du nom de l'ordinateur :
Code:
If ComputerNameBeginsWith("CDI") Then
ConnectDrive2 "X:","\\MyServer\MyShare","Description de ma ressource","utilisateur","motdepasse"
End If
WScript.Quit
'///////////////////////////////////////////////////////////
'// Check if the computer name begins with the given string
'// RDP is supported
Function ComputerNameBeginsWith(Name)
Dim Computer, RDP
Dim objNetwork, objShell
Set objNetwork=WScript.CreateObject("WScript.Network")
Set objShell=CreateObject("WScript.Shell")
Computer=objShell.ExpandEnvironmentStrings("%CLIENTNAME%")
RDP=(Computer<>"" And Computer<>"%CLIENTNAME%" And Computer<>"Console")
If Not RDP Then
Computer=objNetwork.ComputerName
End If
ComputerNameBeginsWith=(InStr(Computer,Name)=1)
End Function
'///////////////////////////////////////////////////////////
'// Connect a drive with credential
function ConnectDrive2(Drive,Path,Description,User,Password)
On Error Resume Next
Dim objNetwork,oScriptShell
Set objNetwork=WScript.CreateObject("WScript.Network")
Set oScriptShell=CreateObject("WScript.Shell")
Set oShell=CreateObject("Shell.Application")
err.number=0
If User="" Then
objNetwork.MapNetworkDrive Drive,Path
Else
objNetwork.MapNetworkDrive Drive,Path,False,User,Password
End If
If err.number<>0 Then
oScriptShell.Popup "Connexion lecteur " & Drive & " (" & Path & ")" & VbCrLf & "Description=" & err.Description & VbCrLf & "Code=" & err.Number,5,"Erreur",64
Else
oShell.NameSpace(Drive).Self.Name=Description
End If
end function
Cdt.