SyntaxHighlighter.config.bloggerMode=true; SyntaxHighlighter.all();

Wednesday, April 27, 2011

How to map network printers via VBS script

There are several task on the IT world that may be quite simple to execute but, imagine you provide service for a large organization and where there 50 different printers across the building and your IT director wants you to configure those printers per floor to specific users... How do you do this? Would you go one by one and set each user's computer manually or will you create a script to ease your life?

Scripting does not just makes it easier to implement but also to make changes that without the script would take lots of hours and manpower...



The following lines contain the script that could accomplish this:


'Created by Tips4teks.blogspot.com
'each line next to the quote won't be ran when you execute the script since it's just a comment.
'The command wscript.echo is used to generate a dialog box with the message of quotes
WScript.Echo "This script maps network printers"


'here you declare your variables
Option Explicit
Dim objNetwork, objPrinter, strUNCPrinter0, strUNCPrinter1, strUNCPrinter2, strUNCPrinter3, strUNCPrinter4, strUNCPrinter5


'These variables contain the server name UNC path of the network printer.
strUNCPrinter0 = "\\server-name\BusinessColor2"
strUNCPrinter1 = "\\server-name\CreativeColor2"
strUNCPrinter2 = "\\server-name\SapPrint2"
strUNCPrinter3 = "\\server-name\BusinessColor1"
strUNCPrinter4 = "\\server-name\CreativeColor1"
strUNCPrinter5 = "\\server-name\SapPrint1"




Set objNetwork = CreateObject("WScript.Network")


'Each one of these lines will map the printer
objNetwork.AddWindowsPrinterConnection strUNCPrinter0
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.AddWindowsPrinterConnection strUNCPrinter2
objNetwork.AddWindowsPrinterConnection strUNCPrinter3
objNetwork.AddWindowsPrinterConnection strUNCPrinter4
objNetwork.AddWindowsPrinterConnection strUNCPrinter5


'The next lines will set a printer as default. 
Set objPrinter = CreateObject("WScript.Network")
objPrinter.SetDefaultPrinter strUNCPrinter0




WScript.Echo "Printers were successfully mapped."
WScript.Quit


Now you got the code but, what do you do with it? Simply copy it as is and paste it on your preferred text editor and save it with extension type "vbs" (ex. map-printers.vbs). Open the script once saved and kaboon shazaam, you got it!

3 comments:

Content belongs to Tips4teks.blogspot.com. All Rights Reserved. Powered by Blogger.