Logon printer script error

Posted on 2008-06-24
Last Modified: 2012-08-13
I have made a vbs printer script that adds printers when a user loggs on, and we have 2 workstation that have physically attached printers that we have shared out. These printers are included in my logon printer script. On the workstations that have no printer attached then the script works fine with no errors. But when the workstations that have the printers attached try and run the script or when they logon then it comes up with a printer script error:

Script: target of the script..
Error: The filename, directory name, or volume label syntax is incorrect.
Source: (null)

Now if you see the code snippet i was logging into workstation2 which has a printer attached with a share name of HP2200_Admin.

So im wondering if there is a way so that no script errors occur no matter what computer you are logging into.

' Printers.vbs

' Simple VBScript to set Printers

' Version 4.0 - 24/06/08

' Author ****, ***

' Modified ****, ***

' ---------------------------------------------------------'

Option Explicit

Dim objNetwork, strUNCPrinter, strUNCPrinter1, strUNCPrinter2, strUNCPrinter3

strUNCPrinter = "\\sbs-svr01\FXDocu236"

strUNCPrinter1 = "\\sbs-svr01\hp2200"

strUNCPrinter2 = "\\workstation1\DYMO"

strUNCPrinter3 = "\\workstation2\HP2200_Admin"

Set objNetwork = CreateObject("WScript.Network") 

objNetwork.AddWindowsPrinterConnection strUNCPrinter

objNetwork.AddWindowsPrinterConnection strUNCPrinter1

objNetwork.AddWindowsPrinterConnection strUNCPrinter2

objNetwork.AddWindowsPrinterConnection strUNCPrinter3


Open in new window

Question by:wyscom

Expert Comment

ID: 21853703

if you do not mind, perhaps you can use the following in a bat file..... it is very simple and straight forward..... you need to just add the line into your login.bat.....

rundll32 printui.dll,PrintUIEntry /q /in /n "\\ServerName\PrinterName"

hope this helps.....
LVL 25

Expert Comment

ID: 21853709
try renaking teh printer with a hyphen instead of an underscore for example hp2200-admin
LVL 24

Accepted Solution

purplepomegranite earned 500 total points
ID: 21853849
The following modification of your code checks the name of the computer before trying to attach it.  This should solve the problem - it is also error trapped in case something slips by - you shouldn't get any errors anymore.
' Printers.vbs

' Simple VBScript to set Printers

' Version 4.0 - 24/06/08

' Author ****, ***

' Modified ****, ***

' ---------------------------------------------------------'

Option Explicit

Dim objNetwork, strUNCPrinter, strUNCPrinter1, strUNCPrinter2, strUNCPrinter3, strComputer

Set objNetwork = CreateObject("WScript.Network") 

strComputer= objNetwork.ComputerName 


AddPrinter "sbs-svr01", "\FXDocu236"

AddPrinter "sbs-svr01", "\hp2200"

AddPrinter "workstation1", "\DYMO"

AddPrinter "workstation2", "\HP2200_Admin"



sub AddPrinter(strComputerAttachedTo, strPath)

	if strComputerAttachedTo=strComputer then exit sub

	on error resume next

	objNetwork.AddWindowsPrinterConnection "\\" & strComputerAttachedTo & strPath

	err.clear ' Just in case

end sub

Open in new window


Author Closing Comment

ID: 31470075
This works fine.
Thanks mate.

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now