Niouzes.org  

Précédent   Niouzes.org > Forum > Newsgroup microsoft.public.fr.* 2 Forum > Newsgroup microsoft.public.fr.scripting
S'inscrire FAQ Membres Calendrier Recherche Messages du jour Marquer les forums comme lus



Réponse

 

LinkBack Outils de la discussion Modes d'affichage
  #1 (permalink)  
Vieux 04/09/2008, 15h34
2Nids
 
Messages: n/a
Par défaut Installation imprimantes selon appartenance au groupe

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
Réponse avec citation
Alt Today
Advertising
Google Adsense
 
This advertising will not be shown
in this way to registered members.
Register your free account today
and become a member on
Niouzes.org
Standard Sponsored Links

Réponse
Tags:



Outils de la discussion
Modes d'affichage

Règles de messages
Vous pouvez ouvrir de nouvelles discussions : nonoui
Vous pouvez envoyer des réponses : nonoui
Vous pouvez insérer des pièces jointes : nonoui
Vous pouvez modifier vos messages : nonoui

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui



Fuseau horaire GMT. Il est actuellement 10h20.

Italiano - German - English - Español


Édité par : vBulletin® version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 © 2007, Crawlability, Inc. Tous droits réservés.
Version française #13 par l'association vBulletin francophone


Politique - Droit - Philosophie - Football - Medicine - Française - Bricolage - Photo - Mac Os X - Divers - Physique - Jardinage
Mecanique - Moto - Photographie - Rail - Route - Aviation - Cinema - Linux - Psychanalyse - Finance - Enigmes - Rugby
Environnement - Histoire - Programmes TV - Education - Travail - Voyages - Windows - Immobilier - Cuisine
Windows XP - Excel - Word - Outlook - Access - Internet Explorer - Office - Vista

Page generated in 0,26338 seconds with 10 queries