PowerShell Ezine, Logon Scripts

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.

ˆ

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 printer http://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

Computer Training Software - Recommended Training VideosGuy Thomas recommends Computer Training Software

Their topics and material are ideal for getting you started with VBScript.  The videos are easy to follow and you can control the pace.  Try their free demo material and then see if you want to buy the full package. See more about VB Script Training CD.


 *


Google

Web  This website

Review of Orion NPMGuy Recommends: Orion's NPM - Network Performance Monitor

Orion's performance monitor is designed for detecting network outages. A network-centric view make it easy to see what's working, and what needs your attention.

This utility guides you through troubleshooting by indicating whether the root cause is faulty equipment or resource overload.

Download a free trial of the Network Performance Monitor

 

Home Copyright © 1999-2009 Computer Performance LTD All rights reserved

Please report a broken link, or an error.