1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
' VB Script Document
option explicit
Dim ConnexionReseau, LecteurReseau
Dim f1, f2, f3, f4, f5, fy, fz, Y, Z, i, j, k
Dim NomAdmin, PasswordAdmin
Dim Serveur, ResultRecherche, CritDeRech
dim TabloY(), TabloZ()
Serveur= "ServeurUSERS"
NomAdmin= "Administrateur"
PasswordAdmin= "MotDePasse"
Y=0
Z=0
CritDeRech="(a(\_|\-)sup|asup)"
Set f1 = CreateObject("Scripting.FileSystemObject")
Set ConnexionReseau = CreateObject("WScript.Network")
Set LecteurReseau=ConnexionReseau.EnumNetworkDrives
ConnexionReseau.MapNetworkDrive "Y:","\\" & Serveur & "\USERS",False,NomAdmin,PasswordAdmin
ConnexionReseau.MapNetworkDrive "Z:","\\" & Serveur & "\USERS_PERSO",False,NomAdmin,PasswordAdmin
Set f2 = f1.GetFolder("Y:")
Set f3 = f1.GetFolder("Z:")
Set fy = f2.SubFolders
Set fz = f3.SubFolders
Function RegExpTest(CritereRecherche, OuChercher)
Dim ExpressRegul, Match, Matches ' Crée les variables.
Set ExpressRegul = New RegExp ' Crée une expression régulière.
ExpressRegul.Pattern = CritereRecherche ' Définit les critères.
ExpressRegul.IgnoreCase = True ' Ignore la casse.
ExpressRegul.Global = True ' Définit une application globale.
Set Matches = ExpressRegul.Execute(OuChercher) ' Lance la recherche.
For Each Match in Matches ' Itère la collection Matches.
ResultRecherche=ResultRecherche & Match.Value & vbCRLF
Next
RegExpTest = ResultRecherche
End Function
'=====================================
'Teste la presence des lecteurs reseau
'=====================================
For i = 0 to LecteurReseau.Count - 1 Step 2
If LecteurReseau.Item(i)="Y:" then
ConnexionReseau.RemoveNetworkDrive "Y:" 'Si Y: existe on le supprime
end if
If LecteurReseau.Item(i)="Z:" then
ConnexionReseau.RemoveNetworkDrive "Z:" 'Si Z: existe on le supprime
end if
Next
'===============================================================
'Affectation des noms de repertoire de Y: dans un tableau TabloY
'===============================================================
For Each f4 in fy
Redim Preserve TabloY(Y)
TabloY(Y)=f4.name
Y=Y+1
Next
'===============================================================
'Affectation des noms de repertoire de Z: dans un tableau TabloZ
'===============================================================
For Each f5 in fz
Redim Preserve TabloZ(Z)
TabloZ(Z)=f5.name
Z=Z+1
Next
For j =Lbound(TabloY) to Ubound(TabloY)
RegExpTest CritDeRech,TabloY(j)
Next
For k =Lbound(TabloZ) to Ubound(TabloZ)
RegExpTest CritDeRech,TabloZ(k)
Next
ConnexionReseau.RemoveNetworkDrive "Y:"
ConnexionReseau.RemoveNetworkDrive "Z:" |
Partager