Sign in with
Sign up | Sign in
Your question

Log on Scripts - Printer Mapping via vbs

Last response: in Networking
Share
June 9, 2010 2:45:16 PM

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.

Quote:

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
June 11, 2010 3:55:58 PM

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
June 11, 2010 4:09:20 PM

also if you want a prompt put this at the end of each printer statment

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