• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7195
  • Last Modified:

Print to LPT1 via CMD (legacy application)

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

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?

Thanks


0
stevendunne
Asked:
stevendunne
  • 5
  • 3
  • 3
  • +2
1 Solution
 
Steve KnightIT ConsultancyCommented:
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
pause
exit

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?
Steve
0
 
sirbountyCommented:
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 127.0.0.1 -n 5 > nul
type c:\temp\myprint > LPT1:
exit

Open in new window

0
 
Steve KnightIT ConsultancyCommented:
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.

Steve
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
sirbountyCommented:
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.")
0
 
stevendunneAuthor Commented:
"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).
0
 
sirbountyCommented:
Yes, but how are you printing to lpt1?  Via the print interface?
What is myprint?  please confirm...
0
 
Steve KnightIT ConsultancyCommented:
Start a cmd.exe prompt on the rdp session.

Type

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.

Steve
0
 
stevendunneAuthor Commented:
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!
0
 
Steve KnightIT ConsultancyCommented:
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
"
0
 
stevendunneAuthor Commented:
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?
0
 
Steve KnightIT ConsultancyCommented:
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.

Steve
0
 
JT92677Commented:
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.


0
 
ee_autoCommented:
Question PAQ'd, 500 points refunded, and stored in the solution database.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now