colly92002
asked on
Server side printing from ASP/WSH
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.Fi leSystemOb ject")
Set objWSHNet = CreateObject("WScript.Netw ork")
objWSHNet.AddWindowsPrinte rConnectio n "//MyPC/HPDescJet970c"
I get an "Access denied" error on the AddWindowsPrinterConnectio n 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.
I am attempting to print from the server using either ASP, or WSH.
In ASP when I try the following:
Set objFS = CreateObject("Scripting.Fi
Set objWSHNet = CreateObject("WScript.Netw
objWSHNet.AddWindowsPrinte
I get an "Access denied" error on the AddWindowsPrinterConnectio
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello again.
The Problem is
objWSHNet.AddWindowsPrinte rConnectio n "//MyPC/HPDescJet970c"
if I do it ONCE (as DOS in WSH):
objWSHNet.AddPrinterConnec tion "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.
The Problem is
objWSHNet.AddWindowsPrinte
if I do it ONCE (as DOS in WSH):
objWSHNet.AddPrinterConnec
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.
There isn't a better way, and it's DELIBERATELY not easy. Would YOU want everybody in the world accessing your printers?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.Fi leSystemOb ject")
Set objPrinter = objFS.CreateTextFile(strPr interPath, 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.Fi leSystemOb ject")
Set objWSHNet = CreateObject("WScript.Netw ork")
objWSHNet.addwindowsprinte rconnectio n "LPT1", strPrinterPath ' this creates a port LPT1 pointing to the printer network name
Set objPrinter = objFS.CreateTextFile(strPr interPath, True)
objPrinter.Write("Test on printer not set up on server until now")
objPrinter.Write vbFormFeed
objPrinter.Close
objWSHNet.RemovePrinterCon nection "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.
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.Fi
Set objPrinter = objFS.CreateTextFile(strPr
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.Fi
Set objWSHNet = CreateObject("WScript.Netw
objWSHNet.addwindowsprinte
Set objPrinter = objFS.CreateTextFile(strPr
objPrinter.Write("Test on printer not set up on server until now")
objPrinter.Write vbFormFeed
objPrinter.Close
objWSHNet.RemovePrinterCon
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.
ASKER
In the second example above, the line:
Set objPrinter = objFS.CreateTextFile(strPr interPath, True)
should read:
Set objPrinter = objFS.CreateTextFile("LPT1 :", True)
I hope this helps someone in the future.
Set objPrinter = objFS.CreateTextFile(strPr
should read:
Set objPrinter = objFS.CreateTextFile("LPT1
I hope this helps someone in the future.
ASKER