Solved

Server side printing from ASP/WSH

Posted on 2004-08-10
8
540 Views
Last Modified: 2008-02-01
Hello.  This is a follow up from a previous question.  System is Windows 2000 server, Classic ASP, VBscript 5.6

I am attempting to print from the server using either ASP, or WSH.

In ASP when I try the following:

Set objFS = CreateObject("Scripting.FileSystemObject")
 Set objWSHNet = CreateObject("WScript.Network")
   
 objWSHNet.AddWindowsPrinterConnection "//MyPC/HPDescJet970c"

I get an "Access denied" error on the AddWindowsPrinterConnection line.

Anyone know why?  The printer address is correct.

Is this the way to do is or would it be better to create a WSH COM object and use that ? Would there be any advantage in that?

Any help appreciated.

0
Comment
Question by:colly92002
[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
8 Comments
 
LVL 15

Accepted Solution

by:
joeposter649 earned 75 total points
ID: 11767516
Sounds like the IUSER_computername account doesn't have permission to access MyPC or the printer on MyPC.
0
 
LVL 15

Author Comment

by:colly92002
ID: 11767864
I shall look into this tommorrow.  Thanks for the reply.
0
 
LVL 13

Assisted Solution

by:davidlars99
davidlars99 earned 50 total points
ID: 11775839
hi,
before you go too far with this question take a look at this huge article:

http://www.asp101.com/articles/john/serversideprint/default.asp

cheers!
 dave
0
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
LVL 15

Author Comment

by:colly92002
ID: 11779398
Hello again.
The Problem is

 objWSHNet.AddWindowsPrinterConnection "//MyPC/HPDescJet970c"

if I do it ONCE (as DOS in WSH):

 objWSHNet.AddPrinterConnection "LPT1", "//MyPC/HPDescJet970c"

and then open up a file system object and print it to it, followed by a ctrl J, its OK (from WSH).

I can only add it once.  Because then it is the registery (via FSO) I can access it via "LTP1:".
The next time it tells me the post is already assigned.

BTW I do have to add ALL permission to the printer on the server so  joeposeter is correct.

This is means I can print to LPT1 via a WSH COM object from ASP but this is surely rubbish?

This seems too complicated, surely this is easy ?  

All I want to do is print to A PRINTER anyway

Also, it gets stuck up waiting for the next CTRL J.

There must be a better way of doing this ?

Thanks for your answers BTW.
0
 
LVL 19

Expert Comment

by:webwoman
ID: 11786221
There isn't a better way, and it's DELIBERATELY not easy. Would YOU want everybody in the world accessing your printers?
0
 
LVL 15

Assisted Solution

by:joeposter649
joeposter649 earned 75 total points
ID: 11786368
Here's some examples and a third party solution...
http://www.sunlink.net/%7Errobbins/aspPrint.htm
0
 
LVL 15

Author Comment

by:colly92002
ID: 11809198
Hello everybody.

I have workes this out.  I knwe it was easy!

To print to a network printer from asp, simply open up a FSO object pointing at the printer:

strPrinterPath = "//MyPc/MyNetworkPrniter"
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objPrinter = objFS.CreateTextFile(strPrinterPath, True)

objPrinter.Write("Hey this is a test!")
objPrinter.Write vbFormFeed
objPrinter.Close


Thats it!  Easy!

If you want to DYNAMICALLY add the printer to the server before printing, then you MUST use WSH (as a COM object) and use:
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objWSHNet = CreateObject("WScript.Network")
objWSHNet.addwindowsprinterconnection  "LPT1", strPrinterPath  ' this creates a port LPT1 pointing to the printer network name
Set objPrinter = objFS.CreateTextFile(strPrinterPath, True)
objPrinter.Write("Test on printer not set up on server until now")
objPrinter.Write vbFormFeed
objPrinter.Close
objWSHNet.RemovePrinterConnection "LPT1:" ' Essential or you cannot add LPT1 again

However I am yet to think of a situation where I would want this, as I am addind the neccessary printers to the server by hand.


I have split the points to all useful commentors, I hope this is acceptable.
0
 
LVL 15

Author Comment

by:colly92002
ID: 11809210
In the second example above, the line:
Set objPrinter = objFS.CreateTextFile(strPrinterPath, True)

should read:
Set objPrinter = objFS.CreateTextFile("LPT1:", True)

I hope this helps someone in the future.
0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to count occurrences of each item in an array.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

691 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