Howto: Print to a usb printer from dos in Windows xp

Дата канвертавання18.04.2016
Памер58.06 Kb.
Created by: Jim Webster

Email address:

If your printer is already attached to a parallel port (also referred to as a “printer port”), then you only need to edit the DosBox Megabuild configuration file.

If your printer is attached to a USB port, then read the two following articles in order to learn how to use the Microsoft Loopback Adapter to re-direct output for a LPTx: port to a USB attached printer. The Microsoft Loopback Adapter is part of MS Windows, so no special software download is required.

DosBox Megabuild installs just like DosBox and the configuration file is called "dosbox-SVN_MB6.conf". These are the lines in this file that I edited, according to their location and my set-up:

# I have com0com installed for use with Emu48. Hence, COM10.

serial1=directserial realport:com10
parallel1=file dev:LPT1
# Change the directory name to match your own.
mount c /DosBox
HOWTO: Print to a USB Printer from DOS in Windows XP

Scott Hanselman has a post on his weblog about getting a shared network printer to work in DOS. That's not really all that tough and actually got me thinking about a similar experience I had recently.

In my previous job I had the great misfortune of having to support a DOS based point-of-sale application. When you sell stuff, you need to give out receipts. We used the nice little T-88's from Epson. Very nice little units that were fairly reliable. When it came time to buy some more, I chose to go with the USB interface rather than parallel because hey, it is the 21st century after all.

What I forgot about was the fact that DOS doesn't know a gosh darn thing about USB. With parallel, it's easy. IJW. Even if you want to use a network printer it's dead simple. Prior to Windows XP you can just go into the printer properties and there's a little button there to capture the printer port and map it to a network printer. In XP you have to know the NET USE command to make it go as the GUI interface disappeared. Odd that.

But what do you do when you don't have the printer connected to the parallel port and you're in a stand-alone type of scenario? Now, the first thought you have is that you'll just share the printer and then use the old NET USE command to capture the printer port and map it to the USB printer. QED. This works. Well, at least it works in the office. Where I happened to have the POS computer plugged into the network to load the software and apply updates etc. But once you disconnect the network cable, the network goes away and so does your shared printer. It doesn't matter that the shared printer is connected to that very machine because as far as Windows is concerned it's on the network and the network has packed it in.

My initial solution to at least get the new store up and running was to simply give them a small 4 port hub to plug into. Windows doesn't care if there are other computers to talk to on the network, so long as the network has punched in and is on the clock. This, as you are no doubt thinking, is a less than an optimal solution.

It's funny the things you forget about or at least put into the deep-archive, tape backup of the mind. I put the issue aside for a few days but it was always nagging at my mind and then one day my wet-ware mainframe finally dredged up something from the archive. LOOPBACK ADAPTER it flashed across my mind. Five or six years ago that would have been the first obvious solution. Sure enough, it's still around in XP.

For the kids out there, the Microsoft Loopback Adapter is basically a software based network adapter that simulates a live network. It was designed for this very purpose. Testing network functionality in the absense of a live network. Anybody out there remember the PWS on Win95? (that's personal webserver - and you could even do ASP on it) Packets basically travel up and down the TCP/IP stack through the adapter and get fed right back to you. So now, as far as Windows is concerned, the network is not only clocked in, but willing to work overtime if neccessary. Sweet.

So here, for your edification and reading enjoyment are step-by-step directions on making this work.

In order to print from DOS in an offline environment like the stores, you will need to do a couple of things.

1) Install the Microsoft Loopback Adapter

a) In Control Panel, double click on Add Hardware.

b) Click Next

c) When the scan finishes, select "Yes, I have already connected the hardware"

d) Click Next

e) Scroll to the bottom of the list and select "Add a new hardware device"

Click Next

f) Select "Install the hardware that I manually select from a list (Advanced)"

g) Click Next

h) Select "Network Adapters"

i) Click Next

j) Select "Microsoft" under the Manufacturer list.

k) Select "Microsoft Loopback Adapter" in the Network Adapter list.

l) Click Next

m) Click Next

n) Click Finish

2) Configure the Adapter
a) The loopback adapter is a virtual network adapter and can be configured the same as a regular network card.
b) Set the adapter to have a static IP address such as

3) Share the printer.

a) I recommend you use a share name that you will remember. I used “Printer” in the new machines that are already deployed.

4) Capture the printer port.

a) NET USE LPT1: \\[Computer Name]\Printer /PERSISTENT:YES

Now, not that I like to encourage this type of behaviour, but if you have done the above and still can't get it to print, you may find some help through one of the articles located here. Dave Just because I can...

Connecting an MS-Dos Application to a Printer on a USB Port on Windows 2000

by Curtis Krauskopf

DataFlex, an MS-Dos application, was written in an era when the only printer ports were serial ports and parallel ports.

A USB port is a completely foreign concept to character mode DataFlex. From DataFlex's point of view, printing to a USB port is as odd as trying to print to the status lights on the keyboard. The DataFlex character mode runtime was never designed to write to a USB port called USB001:.

Despite that, and because of Windows 2000's flexibility, DataFlex and most other MS-Dos applications can be coaxed into printing character mode documents to a USB printer..

The solution is to assign the USB-connected printer a network name, and then to associate that network name with an unused LPT port. The DataFlex program will print to the LPT port and Windows will automatically redirect the job to the USB printer port.

Where to Start



How do I know if I'm logged
in with administrator rights?

Install the Printer

The first step is to install the USB printer normally into Windows. The easiest installation is when Windows 2000 automatically recognizes the printer. This typically happens when you're using a name-brand printer or when the printer had previously been installed on the computer. In most situations, you need to be logged in as an administrator, or as a user with administrator security privileges.


Print the Test Page

Once the printer is installed and the obligatory test pages print correctly, proceed to the following steps.



How do I find the share
name for my computer?

Get the computer's share name

Find the share name for the computer. Share names are also called network names or resource names. On Windows 2000, computers are assigned network names even if they aren't attached to a network. Your computer's network name might have been assigned by the computer manufacturer, or maybe by your IT department, or it might have been assigned when you originally installed Windows 2000. Substitute your computer's resource name with computer_name in these instructions.



How do I find or assign
the share name
for my printer?

Get the printer's share name

Find out the printer's share name (also called resource name or network name). Generally, the name is assigned during printer installation and it might have been assigned automatically. Just like resource (network) names for computers, printers can be assigned share names even if you're not attached to a network. In these instructions, substitute printer_name for the share name assigned to your printer.

Share names can contain letters, digits and a few special characters, like spaces (blanks). Even though share names can contain spaces, I recommend not putting spaces in resource names. The reason is because it's more difficult to use operating system commands when spaces exist in the resource name. Figure 1 shows an example of an operating system command that will not work because the resource name (in this example, a computer cleverly named "my computer name") contains blanks.

net view \\my computer name

Figure 1: This command will not work because spaces are in the computer name.

If the network administrator for your system insists on names with embedded spaces, figure 2 shows a way to do it.

net view "\\my computer name"

Figure 2: This command will work when spaces are embedded in a computer name.

As shown in figure 2, double quotes are used to tell Windows 2000 that the words my computer name belong together. The double quotes are a single double-quote character -- not two single quote characters next to each other. Even though they look nearly the same on the screen, two single quotes will not work.


Choose an LPT port

Pick an unused LPT port.



How do I open an operating system command prompt?

Assign the printer to an LPT port

Open an operating system command prompt. The operating system command in figure 3 assumes that LPT1 is an unused port. At the operating system prompt, enter the command shown in figure 3....

net use LPT1 \\computer_name\printer_name /Persistent:Yes

Figure 3: This command defines a persistent printer connection to LPT1 for a computer cleverly called computer_name and a printer called printer_name.


  • LPT1 is the name of the unused parallel printer port. Note that a colon (:) does not appear after the port name on the command line.

  • \\computer_name is the resource name of the computer that is attached to the USB printer.

  • \printer_name is the resource name (share name) of the USB printer discovered in step 4.

  • /Persistent:Yes denotes that this connection should be reestablished when the system is rebooted. There must not be a space after the slash and after the colon.

If the command line above is wrapping to two lines then widen your browser's window because the above command is on one line.

Figure 4 shows an example of using the command in Figure 3. In Figure 4, the computer is named Dell and the printer is named HP. Figure 4 more clearly shows the spaces between the command's parameters.

net use LPT1 \\Dell\HP /Persistent:Yes

Figure 4: This example shows how to use the command in Figure 3.

Figure 5 is another example of the command in Figure 3, but blanks (spaces) are inside the resource names. In figure 5, the computer's resource name is "Dell Computer" and the printer's name is "HP Printer". HP ink cartridges are an optional accessory.

net use LPT1 "\\Dell Computer\HP Printer" /Persistent:Yes

Figure 5: When one or both of the resource names contain blanks (spaces), surround the entire resource name with double quote characters (") to tell the operating system that the words belong together.

A note about /Persistent:Yes:
The /Persistent:Yes parameter will tell Windows 2000 to reestablish the connection when the system is rebooted. If the printer is not connected to the computer when it boots, Windows 2000 will usually remember the connection anyway. Depending on your system's defaults and security settings, Windows 2000 might even ask if you want to have the printer connection deleted when Windows 2000 can't find the printer anymore.

However, the operating system is not perfect at remembering that you specified /Persistent:Yes. I have seen situations where Windows 2000 seemed to spontaneously decide that the printer connection wouldn't be defined after a reboot even though the printer was connected to the computer and powered on. When that happens, the only way to reestablish the connection is to follow the above instructions. You can bookmark this page to help you remember how to reestablish the printer connection.

The command in figure 3 can be inserted into the autoexec.bat or network login script, whichever is most appropriate for your installation. If you do that, eliminate the /Persistent:Yes parameter because you're making the connection persistent by using the autoexec.bat or network login script.


Optional: Verify the connection

The command in figure 6 shows how to verify that the connection was successful. Enter the command at the operating system prompt.

net view \\computer_name

Figure 6: Verify that the connection was successful.

The following screenshot shows the successful use of these commands.

In the net use command, the Used as column shows that the hpphotos printer has been assigned to LPT1.


Test the printer

The commands in figure 7 show a way to test that the printer has been successfully configured. The ^L part of the command means:

Enter the commands at an operating system prompt. Press the Enter key at the end of each line.

dir > lpt1:
echo ^L > lpt1:

Figure 7: Test the printer connection by sending data to it.

The strange incantation in figure 7 sends a directory listing to the printer. The last page (it might be the only page) of the printout should eject from the printer after you type the ^L key combination. Many thanks to alert reader Eric Meyer for passing along the tip for easily ejecting a partial page. Depending on your printer's configuration and settings, the first page might automatically eject after the 'dir' command and a blank page will eject after the 'echo' command.

If you get an error message similar to this one after using the dir > lpt1: command:

then verify that the printer is turned on and that all of the cables are securely connected to both the printer and the computer.

If nothing printed on the printer and you didn't get a Windows error message box even though you typed the commands exactly as they appear in figure 7, then see the next section, Optional printer configuration.


Optional printer configuration

For DataFlex and other MS-Dos programs, the data stream for the printer port might need to be changed from RAW to Text mode. Symptoms of when you need to do this are:

  • Nothing is printed after a directory listing or when the MS-Dos program printed something to the printer.

  • The printer is printing meaningless and useless information on the pages, such as squiggles, lines and random characters.

  • Only part of the printout is printed by the printer.

To fix these problems, start by opening the printer configuration panel:

  • Start

  • Settings

  • Control Panel

  • Printers

  • Right Click on the Printer to display its context menu

  • Choose Properties from the context menu

Change the data stream from RAW to Text mode. Use these steps:

  • Choose the Advanced tab or button

  • Choose the Print Processor button

  • In the Data Type section, change the data type from RAW to TEXT.

  • Apply and Close the printer panel.

Try the test in Figure 7 again. In all of the Windows 2000 installations I tried, I was always able to get successful results.

Deleting the USB Connection

The command in figure 8 shows how to delete the LPT port connection.

net use LPT1 /Delete

Figure 8: How to delete a USB printer connection.

База данных защищена авторским правом © 2016
звярнуцца да адміністрацыі

    Галоўная старонка