Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1441 connectés 

  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  [VBS] Script d'ajout d'imprimante réseau.

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[VBS] Script d'ajout d'imprimante réseau.

n°1595390
rokuro
Posté le 03-08-2007 à 11:50:58  profilanswer
 

Hello,  :hello:  
 
Alors voila mon problème, en fait je doit faire un script pour une GPO qui ajoute à chaque utilisateurs des imprimantes, mais certains utilisateurs n'ont pas le droit d'imprimer en couleur. J'ai donc partagé deux fois les imprimantes permétants d'imprimer en couleur : une dedier au groupe noir et blanc avec restriction, et une avec tout les droit pour les utilisateurs privilégiés.  :p  
 
Le problème qui se présente pour mon script est qu'il ne fonctionne pas corectement sous Windows 2000, il sort un message d'erreur au démarage, et les imprimante pouvant imprimer en couleur n'apparaissent pas ...  :cry:  
 
Voici mon script :
 
'Déclaration des variables imprimantes
Dim impr_1, impr_2, impr_3, impr_4, impr_5, impr_6, impr_7
 
'Déclaration du Serveur d'impression
PrintSRV = "\\serveur"
 
'Déclaration des Imprimantes dans les variables
PRN1 = "\impr_1"
PRN2 = "\impr_2"
PRN3 = "\impr_3"
PRN4 = "\impr_4"
PRN5 = "\impr_5"
PRN6 = "\impr_6"
PRN7 = "\impr_7"
 
'Flag sur les imprimantes
impr_1 = "no"
impr_2 = "no"
impr_3 = "no"
impr_4 = "no"
impr_5 = "no"
impr_6 = "no"
impr_7 = "no"
 
Set WshNetwork = WScript.CreateObject("WScript.Network" )
set res = CreateObject("Wscript.network" )
Set oPrinters = WshNetwork.EnumPrinterConnections
 
'Verification des droits de l'utilisateur
Function IsMember(sGroup)
Dim sAdsPath,oUser,oGroup,g_oGroupDict,g_oNet  
  'Peupler dictionnaire si pas encore créé
  If IsEmpty(g_oGroupDict) Then
      Set g_oGroupDict=CreateObject("Scripting.Dictionary" )
      g_oGroupDict.CompareMode = vbTextCompare
      sAdsPath = res.UserDomain &"/"& res.UserName
      Set oUser = GetObject("WinNT://"& sAdsPath & ",user" )
       For Each oGroup In oUser.Groups
        g_oGroupDict.Add oGroup.Name, "-"
       Next
      Set oUser = Nothing
  End If
IsMember = CBool(g_oGroupDict.Exists(sGroup))
End Function
 
' Laisser les imprimante dans cet ordre!
For i = 0 to oPrinters.Count - 1 Step 2
  if Ucase(oPrinters.Item(i+1)) = PrintSRV&PRN1 then
    impr_1 = "yes"
  end if
  if UCase(oPrinters.Item(i+1)) = PrintSRV&PRN2 then
    impr_2 = "yes"
  end if
  if UCase(oPrinters.Item(i+1)) = PrintSRV&PRN3 then
    impr_3 = "yes"
  end if
  if UCase(oPrinters.Item(i+1)) = PrintSRV&PRN5 then
    impr_5 = "yes"
  end if
  if UCase(oPrinters.Item(i+1)) = PrintSRV&PRN7 then
    impr_7 = "yes"
  end if
  'Contrôle d'appartenance au groupe d'éditeur Couleur
  If IsMember("GR_PRT_COLOR" ) then
    if UCase(oPrinters.Item(i+1)) = PrintSRV&PRN6 then
      impr_6 = "yes"
    end if
    if UCase(oPrinters.Item(i+1)) = PrintSRV&PRN4 then
      impr_4 = "yes"
    end if
  end if
Next
 
Set WshNetwork = CreateObject("WScript.Network" )
 if impr_1 = "no" then
   WshNetwork.AddWindowsPrinterConnection PrintSRV&PRN1
 end if
 if impr_2 = "no" then
   WshNetwork.AddWindowsPrinterConnection PrintSRV&PRN2
 end if
 if impr_3 = "no" then
   WshNetwork.AddWindowsPrinterConnection PrintSRV&PRN3
 end if
  if impr_5 = "no" then
     WshNetwork.AddWindowsPrinterConnection PrintSRV&PRN5
  end if
  if impr_7 = "no" then
     WshNetwork.AddWindowsPrinterConnection PrintSRV&PRN7
  end if
 
'Contrôle d'appartenance au groupe d'éditeur Couleur
If IsMember("GR_PRT_COLOR" ) then
  if impr_4 = "no" then
     WshNetwork.AddWindowsPrinterConnection PrintSRV&PRN4
  end if
  if impr_6 = "no" then
     WshNetwork.AddWindowsPrinterConnection PrintSRV&PRN6
  end if
end if

 
D'après le message d'erreur, le problème se situe dans la fonction.  :pt1cable:  
 
Je précise que le script fonctionne bien sous XP et que seul les 2 imprimante pour le groupe GR_PRT_COLOR n'apparaissent pas pour les Windows 2000.  :sarcastic:  
 
Voila, merci d'avance.  :D

mood
Publicité
Posté le 03-08-2007 à 11:50:58  profilanswer
 

n°1595514
jpcheck
Pioupiou
Posté le 03-08-2007 à 14:49:16  profilanswer
 

peut êter est-il bon de voir avec un debug.print dans un fichier txt le passage ou non dans une boucle. Ca permettra de voir si tes tests sont pris en compte ou non dans ton OS.

n°1596129
rokuro
Posté le 06-08-2007 à 12:42:26  profilanswer
 

Non le test n'est pas pris en compte sous windows 2000 d'où le message d'erreur au demarage signalant une erreur dans le script.

n°1596524
rokuro
Posté le 07-08-2007 à 10:15:09  profilanswer
 

Personne ne connais un autre script permettant la vérification d'appartenance d'un utilisateur à un groupe fonctionnant sous XP et 2000 ?

n°1597028
rokuro
Posté le 08-08-2007 à 09:34:26  profilanswer
 

Alors ? personne ?  :??:


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  [VBS] Script d'ajout d'imprimante réseau.

 

Sujets relatifs
Detection status imprimanteScript générant un MCD
Resolu [VBS] lister les connexions TCP (comme netstat)[FLASH/Action Script 2.0] Comment modifier un fichier XML
[shell script] Question sur l'init d'une variableCron (tache planifié) et script PHP = bug ?
Wikipedia et Script[VBS] Inserer du texte dans un textarea ?
Script "Se souvenir de moi"[Résolu] Lancement script avec MySQL Query Browser
Plus de sujets relatifs à : [VBS] Script d'ajout d'imprimante réseau.


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR