Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding & removing printers

Status
Not open for further replies.

58sniper

MIS
Apr 25, 2004
9,152
US
I'm new to the vbs world, but have a background in PHP. Based on the Mark's FAQ ( I've put this together, but seem to be missing something somewhere.

Ideally, what I'd like to do is cycle through the networked printers installed on a workstation. If it finds a specific printer installed, it should remove it, and install a printer from a different server. Basically, we're migrating from one server to another. So I'm essentially going to just have a loop for each printer I need to deal with (about 8). Here is what I have:

Code:
ON ERROR RESUME NEXT

Dim WSHShell, WSHNetwork, Path

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
    If WSHPrinters.Item(LOOP_COUNTER +1) = "\\old2003\4050South" Then
      WSHNetwork.RemovePrinterConnection "\\old2003\4050South",True,True    
      WSHNetwork.AddWindowsPrinterConnection "\\new2003\4050North"  
    End If
Next

'Clean Up Memory We Used
set WSHNetwork = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing
  
'Quit the Script
wscript.quit

That does not pass the IF statement, so nothing happens, including no visible errors.

I'm hardcoding the printer names only because they actually change names on the new server.

In a perfect world, I'd like to detect the current default printer so that when I replace it with the printer on the new server, I can set the new default. But that's just a wish.

Ideas as to what I'm doing wrong?

Pat Richard, MCSE(2) MCSA:Messaging, CNA(2)
 
Does anyone know of a script that I can run at logon to DELETE ALL (yes all) printer connections?


Thank you!!!
Brandon
 
yes, examples in my FAQ faq329-5798

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top