Link to home
Create AccountLog in
Avatar of r3helpdesk
r3helpdesk

asked on

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!
Avatar of yehudaha
yehudaha
Flag of Israel image

hey

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

Avatar of SISAnt
SISAnt

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

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.
ASKER CERTIFIED SOLUTION
Avatar of r3helpdesk
r3helpdesk

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of r3helpdesk

ASKER

An answer to the problem is no more needed
The activity was abandoned