manage network printers via logon vbscript

Hello again

I'm trying to create a logon script which should add a few network shared printers from a windows server but beside this I first need to remove all network printers belonging to the actual domain where the workstation is connected and keep existing local printers and network printers from other domains.

For example, we have a domain A with network printers Pa1 and Pa2 and a domain B with with network printers Pb1 and Pb2. Running the script on a notebook named Na1 (which is connected on the domain A) should remove all the printers from domain A (Pa1,Pa2) but not from domain B (Pb1,Pb2) or any other local printers and then should add back Pa1 and Pa2.

Thank you guys!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


i don't think in a script or any other method can identify from with domain a printer was
connected to a computer.

well for the adding the printer bit I think this should do it;

' Example VBScript to map a printer on a server
' Guy Thomas February 2004.
' ******************************
Option Explicit
Dim netPrinter, UNCpath
UNCpath = "\\YourServer\PrinterName"
Set netPrinter = CreateObject("WScript.Network")
netPrinter.AddWindowsPrinterConnection UNCpath
WScript.Echo "Your printer is mapped from : " & UNCpath
' End of example VBScript

' Example VBScript to remove a Printer
' Guy Thomas February 2004.
' ******************************
Option Explicit
Dim DelPrint, UNCpath
UNCpath = "\\YourServer\PrinterName"
Set DelPrint = WScript.CreateObject("WScript.Network")
DelPrint.RemovePrinterConnection UNCpath, true, true
Wscript.Echo "This printer was removed : " & UNCpath

' End of Example Script to remove printer

This is taken from

for further reading in regards to adding/removing also check out

and what yehudaha is saying is correct.

Though you could maybe use an IF command to check the UNC path for information matching domain information.

These are just thoughts though, I'm a beginner with VBScript.
r3helpdeskAuthor Commented:
Yes, I understand your example but the dependence for deleting any printer must be related to the domain and not to the "server\printer_name". What I need in fact is to remove all X connected printers being part of the current domain but not existing printers from other domains already connected to the machine.

The question is how can I identify the domain from which the printer is taking part?

yehudaha and SISAnt  hmm.. I hope you are wrong :)
Thank you!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
r3helpdeskAuthor Commented:
An answer to the problem is no more needed
The activity was abandoned
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.