Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Adding Network Printer

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,55761
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Adding Network Printer
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Adding Network Printer - 1/21/2008 1:02:27 PM   
  thaggai

 

Posts: 8
Score: 0
Joined: 1/21/2008
Status: offline
Any idea why I can add a network printer connection with AddWindowsPrinterConnection  when I hard code the variable \\myserver\printer, but I want to add more then one and don't want to hard code each, but I keep getting "invalid name" error when I try to pull the path from an array and set the variable.

strprinterpath = \\myserver\printer name

addwindowsprinterconnection = strprinterpath  this works but I get the invalid name error when I don't hard code this?
 
 
Post #: 1
 
 RE: Adding Network Printer - 1/21/2008 1:49:27 PM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Post the code you are using when you get the error.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to thaggai)
 
 
Post #: 2
 
 RE: Adding Network Printer - 1/22/2008 1:36:48 AM   
  thaggai

 

Posts: 8
Score: 0
Joined: 1/21/2008
Status: offline
Const ForReading=1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\printers.txt", ForReading)
strFile = objFile.ReadAll
objFile.close
arrPrin = Split(strFile, vbcrlf)
   
For Each strPrin in arrPrin
Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection strPrin
Next
Wscript.Echo "Printer Connections Complete"
Set objShell = Wscript.CreateObject("Wscript.Shell")
ObjShell.Run "control printers"
WScript.Quit

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: Adding Network Printer - 1/22/2008 1:44:20 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
Now we will need to see an example line or two from C:\printers.txt. Also, do you get the error right off the bat or does it create some of the queues first then error out?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to thaggai)
 
 
Post #: 4
 
 RE: Adding Network Printer - 1/22/2008 2:38:41 AM   
  thaggai

 

Posts: 8
Score: 0
Joined: 1/21/2008
Status: offline
Get the error right away

\\servername\printer name
\\servername\printername

Now the printer names do have dashes and some underscores is that what VB doesn' like?

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Adding Network Printer - 1/22/2008 2:42:38 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
Nope, dashes and underlines are fine.

Make this change and see if the output makes sense:

For Each strPrin in arrPrin
   WScript.Echo strPrin
   Set objNetwork = WScript.CreateObject("WScript.Network")
   objNetwork.AddWindowsPrinterConnection strPrin
Next

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to thaggai)
 
 
Post #: 6
 
 RE: Adding Network Printer - 1/22/2008 3:13:35 AM   
  thaggai

 

Posts: 8
Score: 0
Joined: 1/21/2008
Status: offline
I still get the same invalid name error, it does echo the correct path, does the backslashed need to be striped? or reversed?

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: Adding Network Printer - 1/22/2008 3:17:58 AM   
  twilliamsen

 

Posts: 195
Score: 0
Joined: 1/18/2007
Status: offline
Should he/she move the

objFile.close to the line before wscript.quit?

(in reply to thaggai)
 
 
Post #: 8
 
 RE: Adding Network Printer - 1/22/2008 3:28:15 AM   
  thaggai

 

Posts: 8
Score: 0
Joined: 1/21/2008
Status: offline
HE did :) Same results

(in reply to twilliamsen)
 
 
Post #: 9
 
 RE: Adding Network Printer - 1/22/2008 3:28:28 AM   
  ehvbs

 

Posts: 2173
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
No,

  Set objFile = objFSO.OpenTextFile("c:\printers.txt", ForReading) ' opens file
  strFile = objFile.ReadAll  ' slurps all content into strFile
  objFile.close ' we are done with the file, so close it (free resources as sonn a possible)

  arrPrin = Split(strFile, vbcrlf) ' create array fro strFile
  For Each strPrin in arrPrin ' all work is done based on arrPrin

(in reply to twilliamsen)
 
 
Post #: 10
 
 RE: Adding Network Printer - 1/22/2008 3:34:02 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
Ok, change the echo to:

WScript.Echo "|" & strPrin & "|"


What we are trying to do is to make sure there isn't any white space in there. Next, copy everything between the |s in the echo. Then paste it into a run command. See if it opens the queue.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ehvbs)
 
 
Post #: 11
 
 RE: Adding Network Printer - 1/22/2008 5:16:25 AM   
  thaggai

 

Posts: 8
Score: 0
Joined: 1/21/2008
Status: offline
copied and pasted from printers.txt and that opened the printer fine. There is something it doesn't like when its a variable.

(in reply to ebgreen)
 
 
Post #: 12
 
 RE: Adding Network Printer - 1/22/2008 5:25:43 AM   
  ehvbs

 

Posts: 2173
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Looks like we are reduced to Voodoo. So why not look at the VBScript Docs:

  object.AddPrinterConnection(strLocalName, strRemoteName[,bUpdateProfile][,strUser][,strPassword])

so isn't something missing from

   objNetwork.AddWindowsPrinterConnection strPrin

??

(in reply to thaggai)
 
 
Post #: 13
 
 RE: Adding Network Printer - 1/22/2008 5:28:11 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
But I love voodoo.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ehvbs)
 
 
Post #: 14
 
 RE: Adding Network Printer - 1/22/2008 5:37:15 AM   
  thaggai

 

Posts: 8
Score: 0
Joined: 1/21/2008
Status: offline
Has anyone been able to duplicate this and it works?

< Message edited by thaggai -- 1/22/2008 5:45:40 AM >

(in reply to ehvbs)
 
 
Post #: 15
 
 RE: Adding Network Printer - 1/22/2008 5:48:56 AM   
  ehvbs

 

Posts: 2173
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Yes you are right, surely not only Voodoo, but hasty Voodoo from my side.

(in reply to thaggai)
 
 
Post #: 16
 
 RE: Adding Network Printer - 1/22/2008 6:00:13 AM   
  ehvbs

 

Posts: 2173
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
The problem with actually testing is: I'm too much of a coward to
use my system as a test bed for something that is proven to be
problematical.

That's why I feel kind of disqualified. On the other hand side:
If this is strictly local, why

   strprinterpath = \\myserver\printer name

(in reply to ehvbs)
 
 
Post #: 17
 
 RE: Adding Network Printer - 1/22/2008 6:07:49 AM   
  thaggai

 

Posts: 8
Score: 0
Joined: 1/21/2008
Status: offline
Not local really, could have up atleast 10 connections to printers, which would have to be hard coded

(in reply to ehvbs)
 
 
Post #: 18
 
 RE: Adding Network Printer - 1/23/2008 12:15:33 AM   
  twilliamsen

 

Posts: 195
Score: 0
Joined: 1/18/2007
Status: offline
Ok, I just tried your script and it works fine for me...

Is the text file automatically created via an export of some sort or did you write the printers.txt yourself?

I just added to the text file, make sure there is no TABS or spaces anywhere...  I would try to recreate the file

\\server\printername <enter>
\\server\printer2



(in reply to thaggai)
 
 
Post #: 19
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Adding Network Printer Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts