![]() |
| |||||||
| S'inscrire | FAQ | Membres | Calendrier | Recherche | Messages du jour | Marquer les forums comme lus |
![]() |
| LinkBack | Outils de la discussion | Modes d'affichage |
| |||
| Bonjour J'ai réalisé ce script ci dessous pour permettre l'installation des imprimantes utilisateurs selon le groupe AD dont ils dépendent. Les groupes sont nommés comme les imprimantes logés dans un OU spécifique. Le script se déroule de la façon suivante : il efface les imprimantes installées, recherche dans l'ad puis installe les imprimantes. Seulement, voila j'ai un messsage d'erreur "le nom de l'imprimante n'est pas valide" que je ne n'arrive pas Ã*** résoudre. Si vous avez des idées pour résoudre ce souci, n'hésitez pas. Merci Le script ***************************** const ADS_SCOPE_SUBTREE = 2 Dim WshNetwork Dim wshShell Dim clPrinters Dim PrinterServer Set wshShell = CreateObject("Wscript.Shell") Set WshNetwork = WScript.CreateObject("WScript.Network") Set clPrinters = WshNetwork.EnumPrinterConnections userName=WshNetwork.UserName PrinterServer = "ServeurImp" Fields = "memberOf" searchpath="LDAP://OU=SIEGE,DC=domain,DC=fr" query = "SELECT " & Fields & " FROM '" & searchpath & "' WHERE objectcategory='person' AND objectClass='user' AND samAccountName='" & UserName & "'" set conn = CreateObject("ADODB.Connection") conn.Provider = "ADSDSOObject" conn.Open "ADs Provider" set cmd = CreateObject("ADODB.Command") cmd.ActiveConnection = conn cmd.CommandText = query cmd.Properties("SearchScope") = ADS_SCOPE_SUBTREE set rs = cmd.Execute set cmd = nothing do while not (rs.EOF or rs.BOF) memberOf=rs.Fields("memberOf") '************************************************* *********** 'Remove printer '************************************************* *********** For i = 0 to clPrinters.Count -1 i = i + 1 If Left(clPrinters.Item(i),2) = "\\" Then temp = Mid(clPrinters.Item(i),3) printerName = Mid(temp,InStr(temp,"\")+1) isFind = False For each group in memberOf If InStr(group,"Imprimantes") Then groupName = Trim(Mid(group,4,InStr(group,",")-4)) If groupName = printerName Then isFind = True Exit For End If End If Next If Not isFind Then WshShell.RegDelete "HKCU\printers\connections\" & replace(clPrinters.Item(i), "\", ",") & "\" End If End If Next '************************************************* ***********'Add printer '************************************************* *********** For each group in memberOf If InStr(group,"Imprimantes") Then GroupName = Trim(Mid(group,4,InStr(group,",")-4)) GroupeName = searchPrinter(Printername) CreatePrinter GroupeName, driverName End If Next rs.MoveNext loop rs.Close conn.Close set rs = nothing set conn = nothing set WshNetwork=Nothing Set wshShell = Nothing Set clPrinters = Nothing Function searchPrinter(PrinterName) Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCOmmand.ActiveConnection = objConnection objCommand.CommandText = "SELECT driverName FROM 'LDAP://OU=SERVEURS,OU=SIEGE,DC=Domain,DC=fr' WHERE objectClass='printQueue' AND PrinterName='" & PrinterName & "' AND shortServerName='" & PrinterServer & "'" objCommand.Properties("Timeout") = 30 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.Properties("Cache Results") = False Set objRecordSet = objCommand.Execute If objRecordset.EOF = true Then Msgbox objRecordset.EOF else objRecordSet.MoveFirst set objCommand = nothing Do Until objRecordSet.EOF SearchPrinter = objRecordSet.Fields("Drivername").Value objRecordSet.MoveNext Loop End if objRecordSet.Close objConnection.Close set objRecordSet = nothing set objConnection = nothing End Function Sub CreatePrinter(PrinterName, driverName) PrinterPath = "\\" & PrinterServer & "\" & PrinterName For i = 0 to clPrinters.Count -1 i = i + 1 isFind = False If clPrinters.Item(i) = PrinterPath Then isFind = True Exit For End If Next If Not isFind Then WshNetwork.AddWindowsPrinterConnection PrinterPath, driverName End If End Sub ********************* Merci 2nids |
| | ||||
| ||||
| |
![]() |
| Tags: |
| Outils de la discussion | |
| Modes d'affichage | |
| |