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
| Option Explicit
Dim objNetwork, objPrinter, intDrive, intNetLetter, oShell, strvalue, strPrinter
Set objNetwork = CreateObject("WScript.Network")
Set oShell = CreateObject("WScript.Shell")
Set objPrinter = objNetwork.EnumPrinterConnections
'Imprimante par défaut
strValue = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"
strPrinter = oShell.RegRead(strValue)
strPrinter = Split(strPrinter, ",")(0)
'Lecture du tableau
For intDrive = 0 to objPrinter.Count -1 Step 2
intNetLetter = IntNetLetter +1
'Si le nom de l'ancienne imprimante est trouvée, elle est remplacée par la nouvelle
If objPrinter.Item(intDrive +1) = strPrinter then
objNetwork.AddWindowsPrinterConnection "\\srv-impr\MAGLIQUIDE"
objNetwork.SetDefaultPrinter "\\srv-impr\MAGLIQUIDE"
objNetwork.RemovePrinterConnection "\\srv-imp\LXMKMAGML"
elseIf objPrinter.Item(intDrive +1) = "\\srv-imp\LXMKMAGML" then
objNetwork.AddWindowsPrinterConnection "\\srv-impr\MAGLIQUIDE"
objNetwork.RemovePrinterConnection "\\srv-imp\LXMKMAGML"
End If
Next
Wscript.Quit(1) |
Partager