diegomirner
asked on
vbs script need help to delete all printer to add new ones in actual printers script by gpo's
Dear Experts,
I need help in order to modify my actual scrip to be available to delete all printers and publish new ones.I havo no expericence with vbs , could you provide an easy way to modify it ??
all pc's runs windows xp prof
here my actual script , thanks in advance :
scrip :
'
' Printers.vbs - Windows Logon Script.
Set objNetwork = CreateObject("WScript.Netw ork")
objNetwork.AddWindowsPrint erConnecti on "\\data0\CanonIR"
objNetwork.AddWindowsPrint erConnecti on "\\data0\CommBrot"
objNetwork.AddWindowsPrint erConnecti on "\\data0\CommHPColor"
I need help in order to modify my actual scrip to be available to delete all printers and publish new ones.I havo no expericence with vbs , could you provide an easy way to modify it ??
all pc's runs windows xp prof
here my actual script , thanks in advance :
scrip :
'
' Printers.vbs - Windows Logon Script.
Set objNetwork = CreateObject("WScript.Netw
objNetwork.AddWindowsPrint
objNetwork.AddWindowsPrint
objNetwork.AddWindowsPrint
You can also use the following code to list all your printers (if you want to delete the printers then you can replace the wscript.echo section with objNetwork.RemovePrinterCo nnection :
Set WshNetwork = WScript.CreateObject("WScr ipt.Networ k")
Set oPrinters = WshNetwork.EnumPrinterConn ections
WScript.Echo "Network printer mappings:"
For i = 0 to oPrinters.Count - 1 Step 2
WScript.Echo "Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1)
Next
Set WshNetwork = WScript.CreateObject("WScr
Set oPrinters = WshNetwork.EnumPrinterConn
WScript.Echo "Network printer mappings:"
For i = 0 to oPrinters.Count - 1 Step 2
WScript.Echo "Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1)
Next
ASKER
thanks for that , now im geting this error :
in line 3
Error: object required :'objnetwork'
code: 800A01A8
here the new scrip to delete all printers:
'
' Printers.vbs - Windows Logon Script.
objNetwork.RemovePrinterCo nnection "\\data0\CanonIR"
objNetwork.RemovePrinterCo nnection "\\data0\CommBrot"
objNetwork.RemovePrinterCo nnection "\\data0\CommHPColor"
objNetwork.RemovePrinterCo nnection "\\data0\fell1320tn"
objNetwork.RemovePrinterCo nnection "\\data0\FinanBrother"
objNetwork.RemovePrinterCo nnection "\\data0\MembBrother"
objNetwork.RemovePrinterCo nnection "\\data0\Finan_Jean"
objNetwork.RemovePrinterCo nnection "\\data0\BrotherConf"
objNetwork.RemovePrinterCo nnection "\\data0\BrotherHealt"
objNetwork.RemovePrinterCo nnection "\\data0\BrotherExecD"
objNetwork.RemovePrinterCo nnection "\\data0\BrotherMem2"
objNetwork.RemovePrinterCo nnection "\\data0\XeroxDat"
objNetwork.RemovePrinterCo nnection "\\data0\BrothConf2"
objNetwork.RemovePrinterCo nnection "\\data0\BotherHealthCare1 "
objNetwork.RemovePrinterCo nnection "\\data0\PRINTER_14_A"
and them i will create the new one with all new path.
DO you think thats its ok ?
or should i do only one withh all inside ?
i dont know exactly manage with the deletion , should i live it until all users logon ?
could it couse error on logon if all printer has all ready deleted ?
in line 3
Error: object required :'objnetwork'
code: 800A01A8
here the new scrip to delete all printers:
'
' Printers.vbs - Windows Logon Script.
objNetwork.RemovePrinterCo
objNetwork.RemovePrinterCo
objNetwork.RemovePrinterCo
objNetwork.RemovePrinterCo
objNetwork.RemovePrinterCo
objNetwork.RemovePrinterCo
objNetwork.RemovePrinterCo
objNetwork.RemovePrinterCo
objNetwork.RemovePrinterCo
objNetwork.RemovePrinterCo
objNetwork.RemovePrinterCo
objNetwork.RemovePrinterCo
objNetwork.RemovePrinterCo
objNetwork.RemovePrinterCo
objNetwork.RemovePrinterCo
and them i will create the new one with all new path.
DO you think thats its ok ?
or should i do only one withh all inside ?
i dont know exactly manage with the deletion , should i live it until all users logon ?
could it couse error on logon if all printer has all ready deleted ?
You have missed settings the ObjNetwork option at the start:
Set WshNetwork = WScript.CreateObject("WScr ipt.Networ k")
You may have to add the line:
On Error Resume Next
To stop error messages in relation to deleting printers that do not exist, alternatively if you ue the EnumPrinterConnections subroutine I provided this will only remove printers that are connected on the client and would not error, it would also remove printers that are not in the remove list provided
Set WshNetwork = WScript.CreateObject("WScr
You may have to add the line:
On Error Resume Next
To stop error messages in relation to deleting printers that do not exist, alternatively if you ue the EnumPrinterConnections subroutine I provided this will only remove printers that are connected on the client and would not error, it would also remove printers that are not in the remove list provided
ASKER
i will like to use enum + with your subrutine , but i will neen an example about it becouse im lost, can you provide me and ex of the whole script ?
thanks
thanks
'========================= ========== ========== ========== ===
Set objNetwork = CreateObject("Wscript.Netw ork")
'========================= ========== ========== ========== ===
' ENUMERATE PRINTER CONNECTIONS AND DELETE THEM
Set oPrinters = WshNetwork.EnumPrinterConn ections
On Error Resume Next
For i = 0 to oPrinters.Count - 1 Step 2
objNetwork.RemovePrinterCo nnection oPrinters.Item(i+1),true,t rue
Next
On Error Goto 0
'========================= ========== ========== ========== ===
' ADD THE PRINTERS THAT YOU NEED
objNetwork.AddWindowsPrint erConnecti on "\\data0\CanonIR"
objNetwork.AddWindowsPrint erConnecti on "\\data0\CommBrot"
objNetwork.AddWindowsPrint erConnecti on "\\data0\CommHPColor"
Set objNetwork = CreateObject("Wscript.Netw
'=========================
' ENUMERATE PRINTER CONNECTIONS AND DELETE THEM
Set oPrinters = WshNetwork.EnumPrinterConn
On Error Resume Next
For i = 0 to oPrinters.Count - 1 Step 2
objNetwork.RemovePrinterCo
Next
On Error Goto 0
'=========================
' ADD THE PRINTERS THAT YOU NEED
objNetwork.AddWindowsPrint
objNetwork.AddWindowsPrint
objNetwork.AddWindowsPrint
ASKER
i try it , but i have an error at this line :
Set oPrinters = WshNetwork.EnumPrinterConn ections
here all the script i have try , please advice if you see the error , thanks
'
' Printers.vbs - Windows Logon Script.
Set objNetwork = CreateObject("WScript.Netw ork")
objNetwork.AddWindowsPrint erConnecti on "\\data0\CanonIR"
objNetwork.AddWindowsPrint erConnecti on "\\data0\CommBrot"
objNetwork.AddWindowsPrint erConnecti on "\\data0\CommHPColor"
'========================= ========== ========== ========== ===
Set objNetwork = CreateObject("Wscript.Netw ork")
'========================= ========== ========== ========== ===
' ENUMERATE PRINTER CONNECTIONS AND DELETE THEM
Set oPrinters = WshNetwork.EnumPrinterConn ections
On Error Resume Next
For i = 0 to oPrinters.Count - 1 Step 2
objNetwork.RemovePrinterCo nnection oPrinters.Item(i+1),true,t rue
Next
On Error Goto 0
'========================= ========== ========== ========== ===
' ADD THE PRINTERS THAT YOU NEED
objNetwork.AddWindowsPrint erConnecti on "\\data0\CanonIR"
objNetwork.AddWindowsPrint erConnecti on "\\data0\CommBrot"
objNetwork.AddWindowsPrint erConnecti on "\\data0\CommHPColor"
Set oPrinters = WshNetwork.EnumPrinterConn
here all the script i have try , please advice if you see the error , thanks
'
' Printers.vbs - Windows Logon Script.
Set objNetwork = CreateObject("WScript.Netw
objNetwork.AddWindowsPrint
objNetwork.AddWindowsPrint
objNetwork.AddWindowsPrint
'=========================
Set objNetwork = CreateObject("Wscript.Netw
'=========================
' ENUMERATE PRINTER CONNECTIONS AND DELETE THEM
Set oPrinters = WshNetwork.EnumPrinterConn
On Error Resume Next
For i = 0 to oPrinters.Count - 1 Step 2
objNetwork.RemovePrinterCo
Next
On Error Goto 0
'=========================
' ADD THE PRINTERS THAT YOU NEED
objNetwork.AddWindowsPrint
objNetwork.AddWindowsPrint
objNetwork.AddWindowsPrint
Sorry, replace the line:
Set oPrinters = WshNetwork.EnumPrinterConn ections
with:
Set oPrinters = ObjNetwork.EnumPrinterConn ections
Set oPrinters = WshNetwork.EnumPrinterConn
with:
Set oPrinters = ObjNetwork.EnumPrinterConn
ASKER
exelent works , but i have a new error :
in one of the printers it gibes me :
the printer driver is unknown
code 80070705
source:null
its strange , normaly it should take the drive from theserver , any idea ?
in one of the printers it gibes me :
the printer driver is unknown
code 80070705
source:null
its strange , normaly it should take the drive from theserver , any idea ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
well , that looks to complicate for me today , maybe tomorrow , any ways , your solution has work so thanks a lor.
Now i will add a post in order to solve an other problem regarding the same scrip , but this time i need to be sure that all rpinters will work with A4 format, houpe you there to take over of it.
thanks again
Now i will add a post in order to solve an other problem regarding the same scrip , but this time i need to be sure that all rpinters will work with A4 format, houpe you there to take over of it.
thanks again
Set objNetwork = CreateObject("Wscript.Netw
objNetwork.AddWindowsPrint
You can set the default printer using the following command:
objNetwork.SetDefaultPrint
and reomve a printer connection using this:
objNetwork.RemovePrinterCo