PDA

View Full Version : Vbs Print Mapping


budbud
11-22-2005, 05:03 AM
Ok here is the problem I have number of printers in different rooms and all logons move from room to room i also want to change the printers dependent on location I have created this script which works with one problem if the printers are not there it displays an error message.

The script firstly deletes any previous printers on the machine and then assigns one. If the printer is not there the script stops and displays an error message. What is needed here is some sort of check with and if else command but my primitive scripting knowledge only goes so far.

Anyone that could shead some light on the subject would be great.

' Delete and map printers dependent on location
' Lee Dudmish
' 22 Nov 2005
' ------------------------------------------------------'
Option Explicit
Dim objNetwork, strUNCPrinter, strUNCPrinter1, strUNCPrinter2, strUNCPrinter3,

strUNCPrinter4, strUNCPrinter5, strUNCPrinter6, strUNCPrinter7, strUNCPrinter8

'Variables
strUNCPrinter = "\\llc-sr-001\rm3 laser"
strUNCPrinter1 = "\\llc-sr-001\rm3 colour"
strUNCPrinter2 = "\\llc-sr-001\rm7 laser"
strUNCPrinter3 = "\\llc-sr-001\rm7 colour"
strUNCPrinter4 = "\\llc-sr-001\rm8 laser"
strUNCPrinter5 = "\\llc-sr-001\rm8 colour"
strUNCPrinter6 = "\\llc-sr-001\rm11 laser"
strUNCPrinter7 = "\\llc-sr-001\rm11 colour"
strUNCPrinter8 = "\\photosvr\photocopier"

' Section which removes the network printer
Set objNetwork = CreateObject("WScript.Network")
objNetwork.RemovePrinterConnection strUNCPrinter
objNetwork.RemovePrinterConnection strUNCPrinter1
objNetwork.RemovePrinterConnection strUNCPrinter2
objNetwork.RemovePrinterConnection strUNCPrinter3
objNetwork.RemovePrinterConnection strUNCPrinter4
objNetwork.RemovePrinterConnection strUNCPrinter5
objNetwork.RemovePrinterConnection strUNCPrinter6
objNetwork.RemovePrinterConnection strUNCPrinter7
objNetwork.RemovePrinterConnection strUNCPrinter8

'Section which creates the printer connection
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection strUNCPrinter

' Here is where we set the default printer to strUNCPrinter
objNetwork.SetDefaultPrinter strUNCPrinter
WScript.Echo "Default printer set to " & strUNCPrinter

WScript.Quit

jdev
11-22-2005, 01:07 PM
Hi budbud,

This scripting forum is specifically set up for discussion of scripting techniques that are applicable to VanDyke Software products.

You might consider posting the same question to a forum more applicable to your general VBScript question.
Here are a few examples of VBScript forums for which your question might be more applicable:
www.visualbasicscript.com (http://www.visualbasicscript.com/)
ScriptingAnswers.com (http://www.scriptinganswers.com/)
Tek-Tips VBScript Forum (http://www.tek-tips.com/threadminder.cfm?pid=329)
microsoft.public.scripting.vbscript (http://www.dbforums.com/f196/)

--Jake