Link to home
Start Free TrialLog in
Avatar of PhilJMcDougall
PhilJMcDougall

asked on

Need something adding to VBScript for Adding and Deleting Printers

Basically i have some code for a VBScript which adds printers to a clients PC that refers to the print server at the location.

We have an old print server (ICHOLS22) which is being replaced by the new one (GBHOLFP01)

Here is the script i have so far:

On Error Resume Next

Dim net
Dim NetPrinter
Dim Printer

strComputer="."

Set net = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery("Select * from Win32_Printer")

For Each objPrinter in colInstalledPrinters
        Printer = UCase(objPrinter.name)
        If Printer <> "\\GBHOLFP01\PRN1918036" then
            net.RemovePrinterConnection printer
        end If
next

net.AddWindowsPrinterConnection "\\GBHOLFP01\PRN1918036"
net.AddWindowsPrinterConnection "\\GBHOLFP01\PRN5500380"
net.SetDefaultPrinter "\\GBHOLFP01\PRN5500380"

What i need to add to this is a removal of any printer from the clients PC that refers to the old ICHOLS22 printer.

Can anyone help?

Cheers
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image


You already have it set to Remove any Printer Connection not called "\\GBHOLFP01\PRN1918036". If that's not working then remove the line that says "On Error Resume Next" and re-run the script.

HTH

Chris
Avatar of PhilJMcDougall
PhilJMcDougall

ASKER

Yes that works already the bit where i have said don't remove the selected printer, problem is they have other printers on there (random ones that i can't add into the script) from other print servers so i just want to remove printers that recide on ICHOLS22.

net.RemovePrinterConnection "\\ICHOLS22\PRN00500000"
                                           ^ this part to remove
ASKER CERTIFIED SOLUTION
Avatar of zell71
zell71
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Worked a treat. cheers Zell71!