Servers Printing with Word from ASP

Printing with Word from ASP




This article will give you the basics of how to print to a network
printer from Word.
by Gary Chalupa
gchalupa@inetnebr.com

This is the Word version of the Excel
printing article
. Same concept, almost the same code. Microsoft
Word must be installed on the server for any of this to work. Feel
free to contact me with questions, comments or just to
chat.

If you need to print on a regular basis this method is
inefficient. There is a better way documented here.

The
code is heavily commented so it should be easy to follow. Once you
understand the flow, it is easy to adapt this to other applications
as well. There are some preliminary steps you need to take before it
will work. I detail these steps below with the code following
them.

1. Using Print Manager on the server create a new local
port with the name “C:PCL.out”
Step-by-step:

  • Open My Computer/Printers/File Menu/Server Properties
  • Go to the Ports tab
  • Click “Add Port…”
  • Select “Local Port”
  • Click “New Port…”
  • Enter “C:PCL.out”
  • Click “OK”
  • Click “Close”
  • Click “OK”

2. Install a printer with a driver that
will support ALL of the printers you would like to print to.
I recommend the HP Laserjet III. Install this printer as a local
printer on the newly created port, and set it to be the default
printer.

3. Follow method 2 from Q184291.
This will set our printer as the default printer for the system
account. A summary of this process is listed
here.
Step-by-step:

WARNING: Using Registry Editor
incorrectly can cause, system-wide problems that may require you to
install Windows to correct them. Neither I, nor Microsoft, guarantee
that any problems resulting from the use of Registry Editor can be
solved. Use this tool at your own risk.

  • Launch Regedit.exe
  • Select this key: HKEY_CURRENT_USERSoftwareMicrosoftWindows
    NTCurrent VersionDevices
  • From the Registry Menu, click Export Registry File.
  • Save as Devices.reg
  • Select this key: HKEY_CURRENT_USERSoftwareMicrosoftWindows
    NTCurrent VersionPrinterPorts
  • From the Registry Menu, click Export Registry File.
  • Save as PrinterPorts.reg
  • Select this key: HKEY_CURRENT_USERSoftwareMicrosoftWindows
    NTCurrent VersionWindows
  • 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

I used ideas from a
couple of different places to put this together and I need to
mention them.
Word and
ASP

by: Armand Datema

Using
ASP and WSH to Print on Your Intranet

by: Jeff
Sandquist

Formatted Output
using ASP

by: David R. Cline

Q184291
– PRB: COM Objects Fail to Print When Called From
ASP

Microsoft Corporation


Download the code here: Wordprint.zip

Latest Posts

KVM vs VMware Hypervisor Comparison 2020

The KVM vs VMware hypervisor comparison is a classic debate. Hypervisors have increased in usability and power over the last several years as more...

Compare HP’s iLo & Dell’s iDRAC Server Management Tools

Most servers shipped from the major manufacturers today come with some type of out-of-band management tool or baseboard management controller (BMC). Two of the...

Get-MsolUser PowerShell Attributes & Properties

This article has been updated for 2020. Please note that WAAD was retired in 2018, but the cmdlets listed in this article are still...

Microsoft Azure PowerShell Scripts and Commands

Using PowerShell scripts and commands for quickly executing tasks in Windows operating systems offers a number of benefits over traditional scripting languages, such as...

Microsoft Hyper V Review

Microsoft Hyper-V: The Bottom line Microsoft Hyper-V lagged behind VMware's virtualization tool, one of the most popular tools in the space, when it was first...

Related Stories