PowerShell Ezine, Logon Scripts

 

Contact Guy
About Us
Affiliate Program
MCSE Exams
Guy's eBooks
Advice Payment

Guy's Scripting Out-Takes 69 - Option Explicit

Contents for Out-Takes 69 Option Explicit

Example 1 - What we have been talking about

Instructions

  1. Prerequisite you need to substitute your printer share for \\ Alan\HP6
  2. I assume that your client is later than Windows 98.
  3. Copy and paste the script below into notepad.
  4. Save the file with .vbs extension e.g. GuyPrinter.vbs
  5. Double click and then check the message box.
  6. Examine your Printers and Faxes folder for a new printer.
 

' GuyPrinter.vbs
' Author Guy Thomas http://computerperformance.co.uk
' Version 1.2 - April 3rd 2005
' ----------------------------------------'
'
' Purpose of script to map a network printer
' ******************************
Option Explicit
Dim objNetwork, strPrinterPath2
strPrinterPath = "\\Alan\HP6"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection strPrinterPath
WScript.Echo "Connected Printer: " & strPrinterPath
WScript.Quit

' End of example VBScript

 

 

Example 2 - Viscous Comma

 

' GuyPrinter.vbs
' Author Guy Thomas http://computerperformance.co.uk
' Version 1.2 - April 3rd 2005
' ----------------------------------------'
'
' Purpose of script to map a network printer
' ******************************
Option Explicit
Dim objNetwork, strPrinterPath
strPrinterPath = "\\Alan\HP6"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection, strPrinterPath
WScript.Echo "Connected Printer: " & strPrinterPath
WScript.Quit

' End of example VBScript

 

 

Answer 1 Option Explicit

Declare the variable strPrinterPath not strPrinterPath2

Answer 2 No Comma

objNetwork.AddWindowsPrinterConnection, strPrinterPath
 

Correct Version

 

' GuyPrinter.vbs
' Author Guy Thomas http://computerperformance.co.uk
' Version 1.2 - April 3rd 2005
' ----------------------------------------'
'
' Purpose of script to map a network printer
' ******************************
Option Explicit
Dim objNetwork, strPrinterPath
strPrinterPath = "\\Alan\HP6"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection strPrinterPath
WScript.Echo "Connected Printer: " & strPrinterPath
WScript.Quit

' End of example VBScript

 

[ezine/Affiliates/Computer-Training/index.htm]

^


Google
Web  This website

Solarwinds IpMonitorIs Your Server Running Slowly?

Check with SolarWinds ipMonitor

Analyze your network with ipMonitor.  Get a free evaluation copy, and monitor the performance of the servers on your network.
Free Download of SolarWinds ipMonitor