Précédent   Forum des professionnels en informatique > Autres langages > Général Visual Basic 6 et VBScript > VBScript
VBScript Le forum d'entraide sur VBScript. Avant de poster -> La FAQ VBScript
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 20/01/2012, 08h46   #1
Invité régulier
 
Homme
Technicien maintenance
Inscription : janvier 2012
Messages : 69
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Technicien maintenance
Secteur : Administration - Collectivité locale

Informations forums :
Inscription : janvier 2012
Messages : 69
Points : 5
Points : 5
Par défaut VBS - Installation d'une imprimante réseau en fonction de l'O.U AD

Bonjour,

Je souhaiterais créer un script VBS qui m'installe automatiquement une imprimante réseau sur un poste client en fonction de la SOUS O.U ordinateur.

Actuellement j'ai des script DOS pour l'installation des imprimante en fonction des sous o.u ordinateur.

Dans un premier temps je lance 1er script vbs qui va lancer un .cmd en fonction du nom de l'OU de l'ordinateur concerné.

Code :
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
'********** Identification du poste, recherche de sa sous-OU dans l'AD et exécution du fichier
'd'imprimantes correspondant **********
 
On Error Resume Next
 
' Récupération du nom du poste
Set WshNetwork = WScript.CreateObject("WScript.Network")
NomPoste = WshNetwork.ComputerName
 
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
 
'Localisation du poste dans l'AD
objCommand.CommandText = "SELECT ADsPath FROM 'LDAP://OU=XXX,dc=domXXX,dc=XXXX,dc=ad' WHERE objectCategory='computer' AND name='" & NomPoste & "'"
Set objRecordSet = objCommand.Execute
 
'Récupération de la sous-OU du poste
Enreg_AD=objRecordSet.Fields("ADsPath").Value
Dcoupe=split("" & Enreg_AD & "",",")
NomSou=mid(Dcoupe(1),4)
 
'Exécution du fichier d'imprimantes correspondant au poste en fonction de sa sous-OU
Set wshell=CreateObject("WScript.Shell")
wshell.Run"%logonserver%\NETLOGON\Imprimantes\" & NomSou & ".cmd"
J'ai essayé de lancer le .cmd à la fin de mon nouveau VBS mais ça n'a pas marché. C'est pour cela que je veux migrer tout mes fichiers DOS en VBS.

Merci d'avance pour votre aide.
genius2139 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/01/2012, 15h04   #2
Invité régulier
 
Homme
Technicien maintenance
Inscription : janvier 2012
Messages : 69
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Technicien maintenance
Secteur : Administration - Collectivité locale

Informations forums :
Inscription : janvier 2012
Messages : 69
Points : 5
Points : 5
C'est bon j'ai trouvé pour lancer mon .cmd.

Code :
1
2
set WshShell = CreateObject("WScript.Shell")
WSHShell.run ("cmd /c %logonserver%\NETLOGON\UR210\Imprimantes\" & NomSou & ".cmd"), ,true
Je souhaiterais tout de même connaître le script VBS qui gère les sous O.U ordinateurs. Cela pourrait intéresser d'autres personnes!!
genius2139 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/02/2012, 19h38   #3
Invité régulier
 
Homme
Technicien maintenance
Inscription : janvier 2012
Messages : 69
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Technicien maintenance
Secteur : Administration - Collectivité locale

Informations forums :
Inscription : janvier 2012
Messages : 69
Points : 5
Points : 5
Voici ce que j'ai dans un de mes CMD :
Code :
1
2
3
4
cscript %windir%\system32\prnmngr.vbs -x
cscript %windir%\system32\prnmngr.vbs -ac -p "\\monserveur\IMP-123-DELL2330DN"
cscript %windir%\system32\prnmngr.vbs -t -p "\\monserveur\IMP-123-DELL2330DN"
cscript %windir%\system32\prnmngr.vbs -ac -p "\\monserveur\PDFCREATOR"
Je voudrais faire la même chose mais en VBS!!
Merci par avance
genius2139 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/02/2012, 09h10   #4
Membre régulier
 
Homme
Administrateur systèmes et réseaux
Inscription : novembre 2011
Messages : 64
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Administrateur systèmes et réseaux
Secteur : High Tech - Opérateur de télécommunications

Informations forums :
Inscription : novembre 2011
Messages : 64
Points : 74
Points : 74
Salut !

Pour l'ajout d'imprimante réseau, l'objet à créer est "WScript.Network" et la commande à utiliser est "AddWindowsPrinterConnection" :
Code :
1
2
Set objNetwork = CreateObject ("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\Serveur\Printer"
Cachlab est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/02/2012, 09h21   #5
Invité régulier
 
Homme
Technicien maintenance
Inscription : janvier 2012
Messages : 69
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Technicien maintenance
Secteur : Administration - Collectivité locale

Informations forums :
Inscription : janvier 2012
Messages : 69
Points : 5
Points : 5
Citation:
Envoyé par Cachlab Voir le message
Salut !

Pour l'ajout d'imprimante réseau, l'objet à créer est "WScript.Network" et la commande à utiliser est "AddWindowsPrinterConnection" :
Code :
1
2
Set objNetwork = CreateObject ("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\Serveur\Printer"
Salut,

Merci de ta réponse. Comment dois-je lui préciser de me mettre l'imprimante par défaut?
genius2139 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/02/2012, 09h58   #6
Membre régulier
 
Homme
Administrateur systèmes et réseaux
Inscription : novembre 2011
Messages : 64
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Administrateur systèmes et réseaux
Secteur : High Tech - Opérateur de télécommunications

Informations forums :
Inscription : novembre 2011
Messages : 64
Points : 74
Points : 74
La commande est "SetDefaultPrinter" :
Code :
1
2
3
Set objNetwork = CreateObject ("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\Serveur\Printer"
objNetwork.SetDefaultPrinter "\\Serveur\Printer"
Attention, l'imprimante par défaut n'est pas liée au système (HKLM), mais au profil utilisateur (HKCU).
Cachlab est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/02/2012, 13h07   #7
Invité régulier
 
Homme
Technicien maintenance
Inscription : janvier 2012
Messages : 69
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Technicien maintenance
Secteur : Administration - Collectivité locale

Informations forums :
Inscription : janvier 2012
Messages : 69
Points : 5
Points : 5
Citation:
Envoyé par Cachlab Voir le message
La commande est "SetDefaultPrinter" :
Code :
1
2
3
Set objNetwork = CreateObject ("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\Serveur\Printer"
objNetwork.SetDefaultPrinter "\\Serveur\Printer"
Attention, l'imprimante par défaut n'est pas liée au système (HKLM), mais au profil utilisateur (HKCU).
Tout marche sauf la détection du "nomsou"

Au début de mon script je déclare la fonction
Code :
1
2
3
4
'Récupération de la sous-OU du poste
Enreg_AD=objRecordSet.Fields("ADsPath").Value
Dcoupe=split("" & Enreg_AD & "",",")
NomSou=mid(Dcoupe(1),4)
Ensuite je veux l'utiliser pour l'installation de mes imprimantes en fonction des groupes d'ordinateurs mais ça ne marche pas :

Code :
1
2
3
4
5
6
7
8
9
'===============================================================================
'DEPARTEMENT INFORMATIQUE
'===============================================================================
if NomSou("INFO_713") then
objNetwork.AddWindowsPrinterConnection "\\Serveur\Printer1"
objNetwork.AddWindowsPrinterConnection "\\Serveur\Printer2"
objNetwork.AddWindowsPrinterConnection "\\Serveur\Printer3"
objNetwork.SetDefaultPrinter "\\Serveur\Printer2"
end if
J'ai une erreur "type mismatch: 'NomSou'"
genius2139 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/02/2012, 07h02   #8
Invité régulier
 
Homme
Technicien maintenance
Inscription : janvier 2012
Messages : 69
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Technicien maintenance
Secteur : Administration - Collectivité locale

Informations forums :
Inscription : janvier 2012
Messages : 69
Points : 5
Points : 5
Personne peut venir mon secours?!
genius2139 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/02/2012, 09h12   #9
Membre régulier
 
Homme
Administrateur systèmes et réseaux
Inscription : novembre 2011
Messages : 64
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Administrateur systèmes et réseaux
Secteur : High Tech - Opérateur de télécommunications

Informations forums :
Inscription : novembre 2011
Messages : 64
Points : 74
Points : 74
Code :
if NomSou = "INFO_713" then
Cachlab est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/02/2012, 11h28   #10
Invité régulier
 
Homme
Technicien maintenance
Inscription : janvier 2012
Messages : 69
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Technicien maintenance
Secteur : Administration - Collectivité locale

Informations forums :
Inscription : janvier 2012
Messages : 69
Points : 5
Points : 5
Citation:
Envoyé par Cachlab Voir le message
Code :
if NomSou = "INFO_713" then
ça marche!! merci beaucoup
genius2139 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 02h50.


 
 
 
 
Partenaires

Hébergement Web