![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | remove old printers and add new ones Hi guys, I'm a Python guy trying to write a Vbscript (oh no!). Actually, I'm trying to modify an existing script that I found on the internet. I basically need the script to run on workstations, delete printers from our old print server (master), and install the corresponding printer from our new print server (dc01) . I should also mention that the printer names have changes slightly. So far, the script does a great job of deleting printers from Master, but none of the corresponding dc01 printers are installed. Here's the code: Option Explicit On Error Resume Next Dim oAssignedPrinters Dim sComputer Dim sDefaultPrinter Dim oInstalledPrinters Dim oNetwork Dim oPrinter Set oAssignedPrinters = CreateObject("Scripting.Dictionary") Set oNetwork = WScript.CreateObject("Wscript.Network") Set oInstalledPrinters = CreateObject("Scripting.Dictionary") sComputer = oNetwork.ComputerName 'create dictionary of installed printers For Each oPrinter In GetPrinters(sComputer) oInstalledPrinters.Add oPrinter.Name, Null If oPrinter.Default = True Then sDefaultPrinter = oPrinter.Name End If Next 'delete installed printers and create new dictionary for new printers For Each oPrinter In oInstalledPrinters If oPrinter.Name = "PingPong" Then oNetwork.RemovePrinterConnection oPrinter oAssignedPrinters.Add "\\dc01\PingPongHP4350n" ElseIf oPrinter.Name = "medchem4350N" Then oNetwork.RemovePrinterConnection oPrinter oAssignedPrinters.Add "\\dc01\medchemlabHP4350n" End If Next ' Add all printers assigned to the PC. For Each oPrinter In oAssignedPrinters If Not oInstalledPrinters.Exists(oPrinter) Then oNetwork.AddWindowsPrinterConnection oPrinter End If Next 'cleanup Set oAssignedPrinters = Nothing Set oInstalledPrinters = Nothing Set oNetwork = Nothing Set oPrinter = Nothing 'functions Function GetPrinters(sComputer) ' #region On Error Resume Next Dim oWMI Set oWMI = GetObject("winmgmts:\\" & sComputer) Set GetPrinters = oWMI.ExecQuery ("Select * from Win32_Printer") Set oWMI = Nothing End Function Thanks guys! Jesse |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Can't see any printers in the printers folder | Vista General | |||
| Re: Remove all installed printers ?? | PowerShell | |||
| Remove all installed printers ?? | PowerShell | |||
| Unable to Remove Printers in Control Panel | Vista print fax & scan | |||
| Printers Won't Remove/Delete | Vista print fax & scan | |||