Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printer connection acces denied

Status
Not open for further replies.

cfprg

Programmer
Apr 14, 2004
38
US
Hi All,

I am trying to print using windows script. I am using the following code and the error i get is

WSHNetwork.AddPrinterConnection (0x80070005)
Access is denied.


<!--#include virtual="/include/ConnFile.asp"-->
<%

' Get information from our form
'
strPrinterPath = "\\khufu\XEROXdoc" 'Request.Form("printerpath")
strUsername = "Administrator"
strPassword = null
strMessage = "Test Printer123"
Response.Write ("strUsername="&strUsername&"<br>")

' Create FileSystem Object and Windows Script Host Network Object
'
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objWSHNet = CreateObject("WScript.Network")

objWSHNet.AddPrinterConnection "LPT1", strPrinterPath, False, strUsername, strPassword



'objWSHNet.AddWindowsPrinterConnection "\\valinor\Xerox"


' Open Print device as a file using the File System Object
'
Set objPrinter = objFS.CreateTextFile("LPT1:", True)
'
' Send text to print device using the File System Object
'
objPrinter.Write(strMessage)

'
' Close the print device object and trap for errors
'
On Error Resume Next
objPrinter.Close
'
' If an error has occurred while closing the printer connection,
' output what went wrong.
'
If Err Then
Response.Write ("Error # " & CStr(Err.Number) & " " & Err.Description)
Err.Clear
Else

'
' The operation succeeded. Output a confirmation
'
Response.Write("<CENTER>")
Response.Write("<TABLE WIDTH=100% ALIGN=center BORDER=0 CELLSPACING=1 CELLPADDING=1>")
Response.Write("<TR><TD ALIGN=RIGHT><B>Message Sent:</B></TD>")
Response.Write("<TD ALIGN=LEFT>" & strMessage & "</TD></TR>")
Response.Write("<TR><TD ALIGN=RIGHT><B>Path to Network Printer:</B></TD>")
Response.Write("<TD ALIGN=LEFT>" & strPrinterPath & "</TD></TR>")
Response.Write("<TR><TD ALIGN=RIGHT><B>Login ID:</B></TD>")
Response.Write("<TD ALIGN=LEFT>" & strUsername & "</TD></TR>")
Response.Write("</TABLE>")
Response.Write("</CENTER>")
End If

'
' Remove the printer connection
'
objWSHNet.RemovePrinterConnection "LPT1:"
Set objWSHNet = Nothing
Set objFS = Nothing
Set objPrinter = Nothing

%>

<html>
<body>

<table border="1" cellspacing="1" cellpadding="1" width="100%">
<tr align="center" <%=titleColor%>>
<td><b>Test Printer</b></td>
</tr>

</table>

</BODY>
</HTML>
 
try the properties on the printer, security, and add the iusr account

[thumbsup2]DreX
aKa - Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top