Log on Scripts - Printer Mapping via vbs

stevetilsed

Distinguished
Jan 29, 2010
44
0
18,530
Hi all hope you can help,

I'm currently practicing with a few servers and trying to work out how to use login scripts to map printers for users upon log on.

What i need is a VBS script to remove all previous printer entries, map two new shared printers and then set one of them as default.
I have created a LOGON.bat which maps drives and sets the time from the server with an additional line inside ‘CALL \\servername\SYSVOL\curriculum.local\scripts\printer.vbs ‘
Then in the same location as the LOGON.bat i have created a printer.vbs file with the following inside.

on error resume next
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\servername\HP3600N"
objNetwork.AddWindowsPrinterConnection "\\servername\HPCP1515n"
objPrinter.SetDefaultPrinter "\\servername\HP3600N"

This does not seem to give me the desired effect, what am i doing wrong? The printer share names are correct.
This is a 2008 server if that helps at all.

Thanking in advanced,

Steve
 

k3y3n1n

Distinguished
May 20, 2010
198
0
18,690
here a vbs i worked on to map network printers and sets it to one to default and delete the old ones

Option Explicit
Dim netPrinter, UNCpath
UNCpath = "\\my-print-svr\my-printer"
Set netPrinter = CreateObject("WScript.Network")
netPrinter.AddWindowsPrinterConnection UNCpath
' Here is where we set the default printer
netPrinter.SetDefaultPrinter UNCpath

UNCpath = "\\my-print-svr\my-printer2"
netPrinter.AddWindowsPrinterConnection UNCpath
'Adds second printer

Dim objNetwork, strUNCPrinter
strUNCPrinter = "\\my-print\my-printer1"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.RemovePrinterConnection strUNCPrinter
'Deletes printer

Dim objNetwork1, strUNCPrinter1
strUNCPrinter1 = "\\my-print\my-printer2"
Set objNetwork1 = CreateObject("WScript.Network")
objNetwork1.RemovePrinterConnection strUNCPrinter1
'Deletes second printer
Wscript.Quit



I bolded the lines u want to change
 

k3y3n1n

Distinguished
May 20, 2010
198
0
18,690
also if you want a prompt put this at the end of each printer statment

WScript.Echo "Check Printers folder NO: " & strUNCPrinter