• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

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
0
PhilJMcDougall
Asked:
PhilJMcDougall
  • 2
1 Solution
 
Chris DentPowerShell DeveloperCommented:

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
0
 
PhilJMcDougallAuthor Commented:
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
0
 
zell71Commented:
add this for the printers you wish to remove.

If Printer <> "\\GBHOLFP01\PRN1918036" then
            net.RemovePrinterConnection "\\ICHOLS22\PRN00000001"
            net.RemovePrinterConnection "\\ICHOLS22\PRN00000002"
            net.RemovePrinterConnection "\\ICHOLS22\PRN00000003"
            net.RemovePrinterConnection "\\ICHOLS22\PRN00000004"
end If

quick fix
_______
zell71
0
 
PhilJMcDougallAuthor Commented:
Worked a treat. cheers Zell71!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now