PowerShell Ezine, Logon Scripts

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.

ˆ

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.

ˇ

3) Links to scripts at Guy's site.

a) Map home drive http://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.

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

Webcomputerperformance.co.uk

GFi Events Manager

Guy Recommends: GFi EventsManager

Here is a solution to monitor, manage and archive thousands of events that are generated by devices across your entire network.  Get your free evaluation copy of GFI EventsManager.

 

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

Please report a broken link, or an error.