This script has the same core as the first example but with a few extra coding niceties. As you get to know my VBScript style, so you will see my familiar heading section, liberal use of variables, and a WScript.Echo message box to confirm what has happened.
‘ PrintersLong.vbs – Windows Logon Script.
‘ VBScript – Connect a network printer with AddWindowsPrinterConnection
‘ Author Guy Thomas http://computerperformance.co.uk/
‘ Version 2.2 – April 24th 2005
Dim objNetwork, strUNCPrinter
strUNCPrinter = “\\zara\HP LaserJet”
Set objNetwork = CreateObject(“WScript.Network”)
WScript.Echo “Check the Printers folder for : ” & strUNCPrinter
‘ End of Guy’s Windows printer script.
VBS Learning Points
Note 1: Option Explicit forces us to declare variables before we use them in the VBScript. The idea is to reduce spelling mistakes.
Note 2: One reason that I like to employ variables is to make it easier to troubleshoot in general and display messages with WScript.Echo in particular.
Note 3: To help with the line numbers, and to color code your commands get OnScript (free download).