Bonjour,
j'ai un script VBS qui supprime mes lecteurs réseaux et les récréé en fonction de mes groupes utilisateurs.
Il fonctionne bien quand je le lance sur ma session mais en GPO sur ouverture de session il ne voit pas mes lecteurs réseaux et n'en créé pas. Pourtant, mon groupe et mon nom d'utilisateur est bien récupéré.
' En cas d erreur le script continu
'On error resume next
' Declaration des variables
Dim WshNetwork,oShell
' Declaration des objets
Set WshNetwork = WScript.CreateObject("WScript.Network" )
Set oShell = CreateObject("WScript.Shell" )
Log "Debut du programme"
'WScript.Sleep(6000)
' Get a 60 seconds delay
Delay 60
Log "Fin du delai"
' Mappage du lecteur I
If isMember("DSI" ) Then
'Wscript.Echo "DSI"
Log "DSI"
mapDrive "I", "\\192.168.127.1\informatique"
Else
'Wscript.Echo "Pas DSI"
Log "Pas DSI"
End If
' Check for error, then show message.
' If Err.Number <> 0 Then
' Msg = "Error # " & Str(Err.Number) & " was generated by " _
' & Err.Source & Chr(13) & Err.Description
' 'MsgBox Msg, , "Error", Err.Helpfile, Err.HelpContext
' Log Msg
' End If
Log "Fin du programme"
'#####################################################
' Functions secondaires
'#####################################################
Function Delay( seconds )
Dim wshShell, strCmd
Set wshShell = CreateObject( "WScript.Shell" )
strCmd = wshShell.ExpandEnvironmentStrings( "%COMSPEC% /C (TIMEOUT.EXE /T " & seconds & " /NOBREAK)" )
wshShell.Run strCmd, 0, 1
Set wshShell = Nothing
End Function
Function Log(message)
'*** Préparation de l'environnement
Const ForAppending = 8
Set fso = WScript.CreateObject("Scripting.FileSystemObject" )
FichierTXT = "c:\temp\log.txt"
'*** Création du fichier texte "c:\log.txt"
Set NewFichier = fso.OpenTextFile(FichierTXT, ForAppending, True)
'*** Ajout de données dans la variable "data".
data = Day(Now)& "."& Month(Now)& "."& Day(Now)& "."& Year(Now)& " "& Hour(Now)& ":"& Minute(Now)& ":"& Second(Now)& " | " & message
'*** Ecriture des données de la variable "data" dans le fichier texte.
NewFichier.WriteLine(data)
'*** Destruction des objets
NewFichier.Close
Set fso = Nothing
'WScript.Quit
End Function
Function IsMember(groupName)
If IsEmpty(groupListD) then
Set groupListD = CreateObject("Scripting.Dictionary" )
groupListD.CompareMode = 1
ADSPath = EnvString("userdomain" ) & "/" & EnvString("username" )
Log "User : " & ADSPath
Set userPath = GetObject("WinNT://" & ADSPath & ",user" )
For Each listGroup in userPath.Groups
groupListD.Add listGroup.Name, "-"
Next
End if
IsMember = CBool(groupListD.Exists(groupName))
End Function
Function EnvString(variable)
variable = "%" & variable & "%"
EnvString = oShell.ExpandEnvironmentStrings(variable)
End Function
Function mapDrive(letter,path) ' if the letter is already in use, we first unmount the drive
'This is the filesystem object, we'll be using the
'FolderExists method.
Set objFSO = CreateObject("Scripting.FileSystemObject" )
'Wscript.Echo "Mounting " & letter & ":" & path
Log "Mounting " & letter & ":" & path
'Path exists
If objFSO.FolderExists(path) Then
Log "Share Exists"
Else
Log "Share Does Not Exist"
End If
'*** Destruction des objets
Set objFSO = Nothing
Set colDrives = wshNetwork.EnumNetworkDrives
For i = 0 to colDrives.Count-1 Step 2
Log "Lecteur reseau " & i & " " & colDrives.Item(i)
If colDrives.Item(i) = letter & ":" Then
'Fermeture de la liaison
'Wscript.Echo "Fermeture de la liaison"
Log "Fermeture de la liaison " & colDrives.Item(i)
WshNetwork.RemoveNetworkDrive letter & ":", True, True
End If
Next
'Création de la liaison
'Wscript.Echo "Creation de la liaison " & letter & ":" & path
Log "Creation de la liaison " & letter & ":" & path
Err.Clear
On Error Resume Next
wshNetwork.MapNetworkDrive letter & ":" , path, True
'Error traps
If Err <> 0 Then
Select Case Err.Number
Case -2147023694
'Persistent connection so try a second time
On Error Goto 0
WshNetwork.RemoveNetworkDrive strLocalDrive, True, True
WshNetwork.MapNetworkDrive letter & ":" , path, True
Log "Second attempt to map drive " & letter & " to " & path
Case Else
On Error GoTo 0
Log " - ERROR: Failed to map drive " & letter & " to " & path
End Select
Err.Clear
End If
End Function
Message édité par gasimoto le 09-11-2020 à 17:09:40