Guy’s Scripting Ezine 2 – Printers

Contents of Guy’s Scripting Ezine No 2 – Logon Scripts for Printers

N.B. See a better more up-to-date version of this page Here.

1) A secret
2) Logon Scripts for three types of printers
3) Links to more Scripts
4) Logon Script Tip
5) Guy’s Litmus Tests

1) A secret

I will let you into a secret that I discovered when I visited companies and talked to the techies.  What I found was that they all learnt scripting by copying other people’s scripts and just making amendments.  None of these server administrators admitted to learning scripts through classic structured learning. Typical comment was, ‘I have not got time for wading through text books; just give me a script and I’ll make a couple of changes and get the job done’.  Incidentally, these ‘techies who look after the server’, had more different job titles than I have had hot dinners.

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) Logon Scripts for three types of printers

So this week let’s get into some more scripts.
Here are scripts to map three types of printers:

a) NT 4.0, Windows 2003 and XP
b) Windows 95 and Windows 98
c) DOS Based printers

a) NT 4.0, Windows 2003 and XP

This script will provide a user with a network printer. On line 3 the script creates a network Object, and then on line 4, the AddWindowsPrinterConnection Method creates the mapped network drive. The AddWindowsPrinterConnection method takes two parameters: the name of the printer and the UNC path to the printing device.

Instructions

  1. Copy and paste the example below into notepad.exe
  2. IMPORTANT: Change the variable ServerName to a computer on your network.
  3. N.B. Change the PrinterName to the name of a real printer.
  4. Save the script with a .vbs extension, and double click the file to test it.

‘VBScript
‘Script for NT 4.0, Windows 2000 and XP

Set WshNetwork = WScript.CreateObject("WScript.Network")

PrinterPath = "\\printerserver\DefaultPrinter"

WshNetwork.AddWindowsPrinterConnection PrinterPath
 

N.B. See a better more up-to-date version of this page Here.

b) Windows 95, Windows 98 and ME

This script will provide a user with a network printer. On line 3 the script creates a network Object, then on line 4, the AddWindowsPrinterConnection Method makes the connection. The AddWindowsPrinterConnection method takes two parameters: the name of the printer and the UNC path to the printing device.

Note Line 5 PrinterDriver. This is the extra line needed for Windows 9X


‘VBScript
‘Script for Windows 95, 98 and ME

Set WshNetwork = WScript.CreateObject("WScript.Network")

PrinterPath = "\\printerserver\DefaultPrinter"

PrinterDriver = "EPSON Stylus 800"

WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver

Copy and paste the example above into notepad.exe

IMPORTANT: Change the variable ServerName to a computer on your network.

N.B. Change the PrinterName to the name of a real printer.

Save the script with a .vbs extension, and double click the file to test it.

c) DOS Based Printers

This script will provide a user with a network printer. On line 3 the script creates a network Object

Note the method is AddPrinterConnection (no Windows)

Note "LPT1" gets redirected to a mapped network drive.


‘VBScript
‘Script for DOS based printers

Set WshNetwork = WScript.CreateObject("WScript.Network")

WshNetwork.AddPrinterConnection "LPT1", \\Server\Printer1

Copy and paste the example above into notepad.exe

IMPORTANT: Change the variable ServerName to a computer on your network.

N.B. Change the PrinterName to the name of a real printer.

Save the script with a .vbs extension, and double click the file to test it.

Once it works, apply the script to your users through a Group Policy.

Troubleshooting if your script fails
Did you change ServerName to your server name?

Does the PrinterName exist? If so is it shared?

Pay special attention to the syntax "" quotes, ,commas. \ backslashes. One to many or one too few and it just will not work.

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v11.5 v11.5

SolarWinds’ Orion performance monitor will help you discover what’s happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems.  Its also has the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Download a free trial of Solarwinds’ Network Performance Monitor

3) Links to scripts at Guy’s site.

a) Map home drive https://computerperformance.co.uk/Logon/Logon_HomeDir.htm
b) Remove network drive

4) Logon Script Tip

If you apply your scripts through Group Policy, use the GPUpdate command on the XP client or Server 2003 machine. This command refreshes the policy settings and saves a logoff or reboot. (Windows 2000 Pro needs the difficult secedit command.)

5) Guy’s Litmus Tests

I thoroughly recommend my zany Litmus Tests. Each test is fun, yet has a serious learning point. I am sure that there will be at least one test that will suit you. Apply Guy’s Litmus Tests on your servers or on your network.

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