Localiser l'imprimante par défaut

pocema Messages postés 1 Date d'inscription vendredi 9 avril 2004 Statut Membre Dernière intervention 26 février 2005 - 26 févr. 2005 à 14:57
cs_CanisLupus Messages postés 3757 Date d'inscription mardi 23 septembre 2003 Statut Membre Dernière intervention 13 mars 2006 - 26 févr. 2005 à 15:20
Bonjour,

j' utilise cette commande pour lister mes imprimantes : Set oPrinters = WshNetwork.EnumPrinterConnections
j' aimerais localiser l'imprimante définie par défaut ...est-ce possible avec cette commande ??

Voici mon prog, qui me permet de migrer les imprimantes réseaux de mon vieux serveur d'impression vers le new.
Mais lors de le suppression et la création du nouveau lien, je perds l'imprimante définie par défault.
Ce petit prog sera lancé lors du login du user.

dim intranet,chndrf01,Apos,long1,long2,iprinter,srv_name
intranet = "[file://\\INTRANET \\INTRANET]"
chndrf01 = "[file://\\CHNDRF01 \\CHNDRF01]"
apos = 0


Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections

For i = 1 to oPrinters.Count -1 Step 2


if test_serv(srv_name) = intranet THEN 'RECONNAISSANCE DU 1er SERVEUR

Apos=INSTR(1,oPrinters.Item(i-1) ,":") 'DETECTE LA POSITION DU : à partir de la 1é position
long1 = len(oPrinters.Item(i-1)) - Apos 'CALCUL LA LONGUEUR DU NOM DE PARTAGE
long2 = right(oPrinters.Item(i-1),(long1)) 'RECUPERE LE NOM DE PARTAGE
PrinterPath = ("\\intranet"&long2) 'CREE LE PATH POUR LA SUPPRESION
WshNetwork.RemovePrinterConnection PrinterPath, true, true 'SUPPRESSION DU VIEUX RACCOURCI
printerpath = ("\\NEWSERVER"&long2)
WshNetwork.addWindowsPrinterConnection PrinterPath, true, true 'CREATION DU NEW RACCOURCI

end if


if test_serv(srv_name) = chndrf01 THEN 'RECONNAISSANCE DU 2éME SERVEUR

Apos=INSTR(1,oPrinters.Item(i-1) ,":")
long1 = len(oPrinters.Item(i-1)) - Apos
long2 = right(oPrinters.Item(i-1),(long1))
PrinterPath = ("\\chndrf01"&long2)
WshNetwork.RemovePrinterConnection PrinterPath, true, true
printerpath = ("\\NEWSERVER"&long2)
WshNetwork.addWindowsPrinterConnection PrinterPath, true, true


end if




Next


function test_serv(srv_name)


Apos=INSTR(3,oPrinters.Item(i) ,"") 'DETECTE LA POSITION DU \ à partir de la 3é position


if apos <> 0 then
test_serv = LEFT(oPrinters.Item(i),apos-1) 'RECUPERE LE NOM DU SERVEUR
end if

end function

polo

1 réponse

cs_CanisLupus Messages postés 3757 Date d'inscription mardi 23 septembre 2003 Statut Membre Dernière intervention 13 mars 2006 21
26 févr. 2005 à 15:20
En vb6, tu as le simple :

Printer.DeviceName pour le nom de l'imprimante
et
Printer.Port pour la connexion

Loup Gris
0
Rejoignez-nous