Printer Script with AddWindowsPrinterConnection
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 to map a network drive to a UNC Path.
‘ Version 3.1 – by: http://www.tips247.net/tag/mapped-network/
Option Explicit
Dim objNetwork, strUNCPrinter
strUNCPrinter = “\\Printers\HP_printer”
Set objNetwork = CreateObject(“WScript.Network”)
objNetwork.AddWindowsPrinterConnection strUNCPrinter
WScript.Echo “Check the Printers folder for : ” & strUNCPrinter
WScript.Quit
VBS Learning:
- Option Explicit forces us to declare variables before we use them in the VBScript. The idea is to reduce spelling mistakes.
- 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.


