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.Netw ork")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper sonate}!\\ " & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery("S elect * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
Printer = UCase(objPrinter.name)
If Printer <> "\\GBHOLFP01\PRN1918036" then
net.RemovePrinterConnectio n printer
end If
next
net.AddWindowsPrinterConne ction "\\GBHOLFP01\PRN1918036"
net.AddWindowsPrinterConne ction "\\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
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.Netw
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
Set colInstalledPrinters = objWMIService.ExecQuery("S
For Each objPrinter in colInstalledPrinters
Printer = UCase(objPrinter.name)
If Printer <> "\\GBHOLFP01\PRN1918036" then
net.RemovePrinterConnectio
end If
next
net.AddWindowsPrinterConne
net.AddWindowsPrinterConne
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
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.RemovePrinterConnectio n "\\ICHOLS22\PRN00500000"
^ this part to remove
net.RemovePrinterConnectio
^ this part to remove
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked a treat. cheers Zell71!
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