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!
r3helpdeskAsked:
Who is Participating?
 
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!
0
 
yehudahaCommented:
hey

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

0
 
SISAntCommented:
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
WScript.Quit
' 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
WScript.Quit

' End of Example Script to remove printer

This is taken from http://www.computerperformance.co.uk/ezine/ezine16.htm

for further reading in regards to adding/removing also check out http://www.computerperformance.co.uk/Logon/Logon_Remove_Printer.htm

0
 
SISAntCommented:
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.
0
 
r3helpdeskAuthor Commented:
An answer to the problem is no more needed
The activity was abandoned
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.