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!

Printing from ASP 1

Status
Not open for further replies.

Mighty

Programmer
Feb 22, 2001
1,682
US
I have an ASP script which opens an Excel template file, writes some data to it, prints it and then closes without saving. This works fine on my development machine but I cannot get it to print when it runs on my webserver.

I just cannot figure out how to get it working. So I am hoping to try a different method. I am going to try and save the file to the server hard drive first and then hopefully open a shell object and somehow send it to a printer that way. Don't know how to do that though.

Can anyone tell me how to send a job to a printer from a shell object???

Mighty
 
Don't have a printer connected to the server. Am trying to print over the network to a printer selected by the user. All printers have been added to the server and I followed instructions in Microsoft article to add all network printer for SYSTEM account via the registry.

Mighty
 
Was able to use the code below to send a text string to a remote printer. Any way this can be adapted to use the Excel PrintOut method to print to this remote printer??

Code:
<%@ Language=VBScript %>
<%
Option Explicit

Dim strPrinterPath    'Form value for Network Path to Printer
Dim strUsername       'Form value for Username
Dim strPassword       'Form value for Password
Dim strMessage        'Form value for Message to Print
Dim objFS             'VBScript File System Object
Dim objWSHNet         'Windows Script Host Network Object
Dim objPrinter        'Printer Object to stream text to


strPrinterPath = "\\myServer\myPrinter"
strUsername = ""
strPassword = ""
strMessage = "This is a test"

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

' Connect to Network Printer from Windows Script Host
'
objWSHNet.AddPrinterConnection "LPT1", strPrinterPath, False, strUsername, strPassword

'
' 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>")
    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:")
    Response.Write("</B></TD>")
    Response.Write("<TD ALIGN=LEFT>\\cstfilesrv\RightOffice</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

%>


Mighty
 
Managed to get this sorted eventually by setting up all network printers on Local TCP/IP ports on the webserver and doing some minor registry editing.

Mighty
 
Mighty,
I have a similar issue. We use a pocketpc handheld that uses IE to gather some data. I need to print to a remote print server located by the mobile user from the ASP page. I was thinking of doing something similar where I set up the remote printers on the server so I can print to them. Is there anything else that needs to be done? I see you had to make some registry changes. Why was that? Any help would be much appreciated.

Thanks
Alex
 
Hi cybercop,

Not sure I am going to be a huge amount of help to you as I can't really remember. As far as I can recall, I did the following:

1. Made registry changes as SYSTEM account needs to be able to print to network printer. Followed this:
Launch Regedit.exe
Select this key: HKEY_CURRENT_USER\Software\Microsoft\Windows NT\Current Version\Devices
From the Registry Menu, click Export Registry File.
Save as Devices.reg
Select this key: HKEY_CURRENT_USER\Software\Microsoft\Windows NT\Current Version\PrinterPorts
From the Registry Menu, click Export Registry File.
Save as PrinterPorts.reg
Select this key: HKEY_CURRENT_USER\Software\Microsoft\Windows NT\Current Version\Windows
From the Registry Menu, click Export Registry File.
Save as Windows.reg
From the Start Button, select Run. Type "Notepad Devices.reg" and hit enter.
Replace the text "HKEY_CURRENT_USER" with "HKEY_USERS\.DEFAULT"
Save the file and exit.
From the Start Button, select Run. Type "Notepad PrinterPorts.reg" and hit enter.
Replace the text "HKEY_CURRENT_USER" with "HKEY_USERS\.DEFAULT"
Save the file and exit.
From the Start Button, select Run. Type "Notepad Windows.reg" and hit enter.
Replace the text "HKEY_CURRENT_USER" with "HKEY_USERS\.DEFAULT"
Save the file and exit.
From the Start Button, select Run. Type "c:\" and hit enter.
Double click Devices.reg
Double click PrinterPorts.reg
Double click Windows.reg

2. Set up all the printers I required as local printers on the webserver - but using a TCP/IP port

3. Set my code to print the document to the name I assigned to the printer.

I was printing out Excel documents and this worked fine for me. I hope this is of some help to you.

Mighty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top