Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Logon printer script error

Posted on 2008-06-24
4
Medium Priority
?
1,357 Views
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..
Line:20
Char:1
Error: The filename, directory name, or volume label syntax is incorrect.
Code:8007007B
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
 
WScript.Quit

Open in new window

0
Comment
Question by:wyscom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 4

Expert Comment

by:bdpsg
ID: 21853703
hi,

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.....
0
 
LVL 25

Expert Comment

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

Accepted Solution

by:
purplepomegranite earned 2000 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"
 
WScript.Quit
 
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

0
 

Author Closing Comment

by:wyscom
ID: 31470075
This works fine.
Thanks mate.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

718 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