The Database Managers, Inc.

Contact The Database Managers, Inc.


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

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 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:

  • press and hold the control key and tap the L key
  • release the control key

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.

Readers of this page also want to know...

The Database Managers helps companies to:
  •  become more profitable
  •  grow their business
  •  fix programs that are behaving badly
  •  write new programs to solve business problems
  • do more with fewer resources

Copyright 2003-2010 The Database Managers, Inc.

Other Popular DataFlex topics at The Database Managers, Inc.:

DataFlex: Tips | Freeware | WebApp Server | Books | Links
Services | Programming | Contact Us | Recent Updates

Send feedback to: