Question Locked

Windows Script sybtax Error

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

hello everybody,

i am trying to run a script that will install 3 printers at users logon (yes, it is necessary)
but i keep getting this error, and i dont know where the syntax error is.
this is the error:
"Script:
\\mydomain\sysvol\mydomain\policies\{ridiculously long key}\user\scripts\logon\printer.vbs
Line: 16
Char: 1
Error: The filename, directory name. or volume syntax is incorrect.
Code: 800700B
Source: (null)"
-----------------------------------------------
and this is the script:

' VBScript - Connect network printers
' May 2008
' ----------------------------------------------------------'
Option Explicit
Dim objNetwork
'Dim strLocal
Dim Printer1 'continental
Dim Printer2 'JetBlue
Dim Printer3 'British Airways

Set objNetwork = CreateObject("WScript.Network")
Printer1 = "\\scdc\continental"
Printer2 = "\\scdc\JetBlue"
Printer3 = "\\scdc\British Airways"

objNetwork.AddWindowsPrinterConnection Printer1
objNetwork.AddWindowsPrinterConnection Printer2
objNetwork.AddWindowsPrinterConnection Printer3

WScript.Quit

' End script.
-----------------------------------------------
help please.

5 replies

by bizzo

Try amending the line

Set objNetwork = CreateObject("WScript.Network")

to

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

by Member 30634329

The script might be erroring out due to the space in the printer name of Printer3.
Try remarking out the Printer3 variable assignment and AddWindowsPrinterConnection lines and see if it works.
If it does, then you need to add double-quotes to the Printer3 variable. remember for vbscript to recognize a double-quote in a string it must be repeated twice:

Printer3="""\\scdc\British Airways"""

by scott_heath

\ is an escape character. You use towo together to be one, kind of like "" for double quotes within a string. Make these changes:

Printer1 = "\\\\scdc\\continental"
Printer2 = "\\\\scdc\\JetBlue"
Printer3 = "\\\\scdc\\British Airways"

Cheers,
Scott

Visit my blog @
http://scottisageek.spaces.live.com

This discussion is closed to new replies.