Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - remove old printers and add new ones

Reply
 
Old 09-23-2009   #1 (permalink)
Johnny Utah


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46