Guy’s Scripting Ezine 5 – Printers

Contents of Guy’s Scripting Ezine 5 – Printers

1) This Week’s Secret
2) Map network printers
3) Learning points
4) Troubleshooting error messages
5) Special Request

1) This Week’s Secret

I will let you into a secret; my most difficult logon script has been to map multiple printers.

Tom, I thank you for drawing my attention to the printer script problems, and gently nudging me to investigate solutions.

Once again, I have been grappling with CGI scripts. Learning a new scripting language has been a humbling process and it has brought home the need to cover error messages with my own scripts. Now I realize that when you are in a hurry that you just want to copy and paste the scripts. However, if you wish to learn how VBscripts works, then there is no gain without pain, and that pain is deciphering error messages.

Guy Recommends: The Free IP Address Tracker (IPAT) IP Tracker

Calculating IP Address ranges is a black art, which many network managers solve by creating custom Excel spreadsheets.  IPAT cracks this problem of allocating IP addresses in networks in two ways:

For Mr Organized there is a nifty subnet calculator, you enter the network address and the subnet mask, then IPAT works out the usable addresses and their ranges. 

For Mr Lazy IPAT discovers and then displays the IP addresses of existing computers. Download the Free IP Address Tracker

2) Map Network Printers

The purpose of this script is to map more than one printer.
INSTRUCTIONS
Copy the lines below, paste into notepad, save with .vbs extension example printerduo.vbs. Prerequisites: you need two network printers. If need be, create a "pretend" printer with the add printers wizard.

Script code:


‘ VBScript.
‘ A script to map two network printers
‘ Remember to substitute your server names for lucy4
‘ What are your printer names?
‘ Crucial point a carriage return between the printers
Dim net
Set net = CreateObject("WScript.Network")
net.AddWindowsPrinterConnection "\\lucy4\dotty", "DotMatrix"
net.AddWindowsPrinterConnection "\\lucy4\lazy", "Color2"
 

3) Learning Points

"Dim net" declares net as a variable. (dim print would work just as well)
set net = createobject ("wscript.network"). (This line is creating "net" and setting as a network object. Other objects would be user or computer)
net.AddWindowsPrinterConnection "\\lucy4\dotty", "Dot Matrix (AddWindowsPrinterConnection is a method telling it what do. MapNetworkDrive is another method)
Unlike variables, you cannot make up your own methods, they are built in and you just learn or collect them to use in your scripts.

Here is a reference to get more ideas, for example to the default printerhttps://computerperformance.co.uk/Logon/LogonScript_Printer.htm

4) Troubleshooting error messages.

Line: 9
Char: 71

Expected end of statement
Code 800A0401

Clues. The error is to be found on the 9th Line down – blank lines ARE counted, and remark lines are counted. 71st character – again including blanks. This is the area where the problem is located.

What can "Expected end of statement" mean? Some things missing? So try an extra carriage return and bingo – it works. (Actually I first tried a comma, but that did not work.)

Code 800A0401. All error codes begin with 800, so pay close attention to the last 5 characters. Search Google for "Code 800A0401" sometimes you find useful clues, often its just other people with the same problem! If a Google search cannot help then do contact me.

References for more Error messages: 0800xxxx Error Codes

See more about logon printer VBScripts

Logon Printer Methods  • Ezines  • Logon Map Printer  • Logon Scripts  • Tool Kit

Ezine 2 Printers  • Ezine 5 Printers  • Ezine 16 Printers  • Ezine 17 Printers

Ezine 116 Printers Two  •Ezine 118 Printer network  •PowerShell Printers