Print to LPT1 via CMD (legacy application)

Posted on 2009-04-14
Last Modified: 2013-11-21
I have an old application that's used through RDP (Windows Srv 2003).  The session is created from a PC with a Label Printer attached via LPT1.

The application runs the following batch file when trying to print a labelg:-

type c:\temp\labeldef.rpt > LPT1:
type c:\temp\myprint > LPT1:

On the 2nd line when trying to access the file 'myprint' the following error comes up (and nothing prints).

'the process cannot access the file because it is being used by another process'

What process?  How do I narrow this down?

This process works fine on a Windows 2000 server, just trying to move onto 2003 for first time.  Also, I can send a test page back to the label print from the RDP session, so it's connected via the session.

Any ideas with this please?


Question by:stevendunne
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
  • +2
LVL 43

Expert Comment

by:Steve Knight
ID: 24137316
Assuming that lpt1: is not the issue here (and it could be), maybe the application does not close the myprint file before it calls this batch process?  Can you amend this to try doing just

rem type c:\temp\labeldef.rpt > LPT1:
type c:\temp\myprint

so you can see if the file will show to the screen (in this case it may be accessing lpt1: that is the issue).  Not sure if the LPT1: port will map OK
through RDP anyway without using a share on the user PC and a NET USE anyway?

Is this for one user or multiple btw?
LVL 67

Expert Comment

ID: 24137344
It could be that the rpt file is taking too long?
I assume the 'myprint' is a simple line feed?  Which is probably needed for that printer.
So, you can fake a delay by using the attached (if you have networking hardware installed).

type c:\temp\labeldef.rpt > LPT1:
ping -n 5 > nul
type c:\temp\myprint > LPT1:

Open in new window

LVL 43

Expert Comment

by:Steve Knight
ID: 24137690
Good point.  I had assumed it might be the .rpt file was setting the printer up and the myprint was the "variable" text to print.

Do you happen to know if LPT1: will actually map through RDP like this OK, I know you can map serial ports and printers but I didn't think it "appeared" as LPT1: to the server side - everything I have setup as networked so nothing to try on at the mo.

Office 365 Training for IT Pros

Learn how to provision Office 365 tenants, synchronize your on-premise Active Directory, and implement Single Sign-On.

LVL 67

Expert Comment

ID: 24137716
Yeah, I was second-guessing myself on that as well.
Just tested here - I cannot access lpt1 from an rdp session in my environment ("LPT1: is not a recognized device.")

Author Comment

ID: 24137925
"so you can see if the file will show to the screen (in this case it may be accessing lpt1: that is the issue)"

I've done this, and the file contents does show on screen.  What does this suggeest?

"Not sure if the LPT1: port will map OK through RDP anyway without using a share on the user PC and a NET USE anyway?"

I'm able to print a test page from the RDP session, back to the printer attached to the local PC  (LPT1).
LVL 67

Expert Comment

ID: 24138015
Yes, but how are you printing to lpt1?  Via the print interface?
What is myprint?  please confirm...
LVL 43

Expert Comment

by:Steve Knight
ID: 24138064
Start a cmd.exe prompt on the rdp session.


echo Testing > lpt1:
echo (Press control and L) > lpt1:   (doing what it says of course nt typing).
Does it come out?

I suspect not.

I think you need to share the printer on the workstation and then connect it for the user with a net use lpt1: \\userpc\printername /persistent:no or get it connected through a print server box.


Author Comment

ID: 24138091
I will try the above.  The odd thing is, this process works fine on a Windows 2000 server.  I guess Win2003 has changed, and just says no!
LVL 43

Expert Comment

by:Steve Knight
ID: 24138165
Pretty sure there used to be a checkbox "LPT" mapping in RDP client but not there in the version I have now, just "printer mapping".

From another article:
2. on server side run TSCC.msc and navigate to RDP-TCP Properties => click
Client Settings tab

verify you have "Use connection settings from user settings" checked

verify check boxes for Printer mapping, LPT port mapping and COM port
mapping under section "Disable the following:" are NOT checked

Author Comment

ID: 24167812
Thanks for your help, but I managed to get this resolved with the following commands:-

copy c:\temp\labeldef.rpt LPT1

copy c:\temp\myprint LPT1

Shall I split the points, u happy with that?
LVL 43

Expert Comment

by:Steve Knight
ID: 24168108
Ahh thats probably because sending to LPT1: is different to LPT1, also some people use LPT1.DOS - I think one is handled as a file, the LPT1: as a device.  

Split them or close it, upto you.


Expert Comment

ID: 24381679
Basically you are trying to connect LPT1 to a printer on the WIndows 2003 machine.

Step 1: Be sure you can print to the printer from Windows (no doubt you can)
Step 2: Share the printer with a simple name with no spaces, like "DOSPRINT"
Step 3: Find out your WIndows machine full computer name, e.g. Right click "My computer"
then Properties, then Computer name, then look at Full Computer name. Change it to something
short if it's long or has spaces, e.g. "mywin2003"

Now go to the CMD prompt in WIndows

Net View  mywin2003

You should see one of devices is "DOSPRINT"

The rest is easy

net use lpt1:  \\mywin2003\dosprint

What you've done is make lpt1: direct all it's output to the shared windows printer that works as
a shared printer (even though you're not really sharing it with anyone else).

As strange as this sounds, it works, and has the advantage of using Windows to spool jobs,
handle the details of printing things coming from DOS. You can even print to a USB printer
that DOS cannot print to directly.

Check the printer setting using:  net use

If you want to disconnect the LPT1, use    net use lpt1:  /delete
then   net use    again, to see if it's no longer connected.

hope this helps.

The key is to share the printer first, and attach the DOS box to the shared device.

This will keep LPT1 attached to the printer for as long as the Windows 2003 system is running, until either you reboot, or use the /delete switch on the net use command.


Accepted Solution

ee_auto earned 0 total points
ID: 24941057
Question PAQ'd, 500 points refunded, and stored in the solution database.

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Anything wrong with Window server backup? 8 139
Seatools For Dos (Just shows FreeDos) 21 151
Recover from a ISCSI Share In Windows 2 67
Server 2016 FTP 5 22
Some time ago I faced the need to use a uniform folder structure that spanned across numerous sites of an enterprise to be used as a common repository for the Software packages of the Configuration Manager 2007 infrastructure. Because the procedu…
Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question