How do I redirect DOS printer output to local printer?

  • Thread starter Thread starter Steve Smith
  • Start date Start date
S

Steve Smith

I need to be able to print from an old DOS program running on Windows 2000 Terminal Server to a local printer connected the a Windows 2000 Remote Desktop client which is located in another office and connected via the Internet. The DOS program is set to only print to LPT1 and this can not be changed. The Win2K Terminal Server server already had a printer connected to LPT1 and it is this printer that receives the output from the DOS program. How can I redirect the printer output from this DOS program to print to the local printer on the TS client?

Thanks,
Steve Smith
 
When you connect to the TS your local printer is autocreated on your TS
session.
What you must do is on your session, SHARE this autocreated printer as
whatever you name it.
Then open a command prompt window on the TS and type NET USE LPT1:
\\YOUR_TS_NAME\THE_SHARE_NAME_YOU_GAVE.
This will allow you to print from the DOS app to the local printer.
I wrote a script I posted here MANY time that automates this process and
does it every single time a user logs in. The user must be power user though
thanks to some TS limitations on this area.

--
Cláudio Rodrigues, MVP
Windows 2000/NT Server
Terminal Services

http://www.terminal-services.NET

-> The only Terminal Services Client for DOS.
-> The only customized RDP5.1 client with the close button disabled! :-)
-> Developers of SecureRDP, the BEST security utility for TS!

Do NOT email me directly UNLESS YOU KNOW ME or you are a Microsoft
MVP/Employee.
Use my support page on my website to submit your questions directly.

I need to be able to print from an old DOS program running on Windows 2000
Terminal Server to a local printer connected the a Windows 2000 Remote
Desktop client which is located in another office and connected via the
Internet. The DOS program is set to only print to LPT1 and this can not be
changed. The Win2K Terminal Server server already had a printer connected to
LPT1 and it is this printer that receives the output from the DOS program.
How can I redirect the printer output from this DOS program to print to the
local printer on the TS client?

Thanks,
Steve Smith
 
Cláudio Rodrigues said:
When you connect to the TS your local printer is autocreated on your TS
session.
What you must do is on your session, SHARE this autocreated printer as
whatever you name it.
Then open a command prompt window on the TS and type NET USE LPT1:
\\YOUR_TS_NAME\THE_SHARE_NAME_YOU_GAVE.
This will allow you to print from the DOS app to the local printer.
I wrote a script I posted here MANY time that automates this process and
does it every single time a user logs in. The user must be power user though
thanks to some TS limitations on this area.

Thank you very much Cláudio. I've found your script and I'm pasting it below for the benefit of others.

Steve Smith
What you need to do is to share the printer the TS MAPPED for the user
(automatically done) and then capture the LPT port.
This script will do that automatically:

rem get the session ID out of the %TEMP% environment variable
for /f "eol=; tokens=6 delims=\ " %%i in ("%TEMP%") do set TSSID=%%i
rem construct the printer name
set TSPrinterName=PrinterName/%CLIENTNAME%/Session %TSSID%
rem share the printer
rundll32 printui.dll,PrintUIEntry /Xs /n "%TSPrinterName%" sharename
"TSPrinter%TSSID%" attributes +Shared
net use lpt1: /DELETE
net use lpt1: \\127.0.0.1\TSPrinter%TSSID%
 
I would very much like to use Cláudio Rodrigues' scrip but I get an error message that says:
"printer rundll command failed. You either entered and printer name that was not correct or the specified printer is no longer connected to the server." I can print from DOS just fine when I open a command prompt window and type
NET USE LPT1: \\YOUR_TS_NAME\THE_SHARE_NAME_YOU_GAVE.
But, I'd really like to automate the process. I know it's something simple. I guess I'm missing something.

Do I need to edit the script? If so, can anyone tell me specifically what parts of this script I should edit? Perhaps I need to specify my printer name or share name by substituting them in the script below? I've numbed the lines to make it easier to reference them.

Thanks,
Steve Smith

rem get the session ID out of the %TEMP% environment variable
1. for /f "eol=; tokens=6 delims=\ " %%i in ("%TEMP%") do set TSSID=%%i
rem construct the printer name
2. set TSPrinterName=PrinterName/%CLIENTNAME%/Session %TSSID%
rem share the printer
3. rundll32 printui.dll,PrintUIEntry /Xs /n "%TSPrinterName%" sharename "TSPrinter%TSSID%" attributes +Shared
4. net use lpt1: /DELETE
5 net use lpt1: \\127.0.0.1\TSPrinter%TSSID%
 
Use this script:

; Get the default printer name and share/map it for DOS apps.
; By Cláudio Rodrigues, http://www.Terminal-Services.NET
; Example String: HP LaserJet 4Si/CLAUDIOXP/Session 1,winspool,TS002

;Reads the default printer from the registry.
$DefaultPrinter = ReadValue("HKEY_CURRENT_USER\Software\Microsoft\Windows
NT\CurrentVersion\Windows","Device")

;Extracts the printer name on the TS. Example: HP LaserJet
4Si/CLAUDIOXP/Session 1
$WhereisComma = InStr("$DefaultPrinter",",") - 1
$TSPrinterName = Left("$DefaultPrinter","$WhereisComma")

;Extracts the machine name/Session ID. Example: CLAUDIOXP/Session 1
$WhereisSlash = InStr("$TSPrinterName","/") - 1
$MachineAndSSID = Left("$DefaultPrinter","$WhereisSlash")

;Extracts the Session ID only from the string above. Example: 1
$PosTemp = InStr("$TSPrinterName","/")
$EndTemp = Len("$TSPrinterName") - $PosTemp
$TempStr = Right("$TSPrinterName","$EndTemp")
$PosTemp = InStr("$TempStr","/")
$EndTemp = Len("$TempStr") - $PosTemp
$TempStr = Right("$TempStr","$EndTemp")
$Pos2 = InStr("$TempStr"," ")
$End3 = Len("$TempStr") - $Pos2
$SSID = Right("$TempStr","$End3")

$ShareName = "TSPrinter" + $SSID
$TSPrinterName = chr(34) + $TSPrinterName + chr(34)

If Len($LocalPrinter) <> 0
then
$TSPrinterName = chr(34) + $LocalPrinter + $MachineAndSSID + chr(34)
EndIf

;Shares the printer.
USE LPT1: /DELETE
Shell 'rundll32 printui.dll,PrintUIEntry /Xs /n $TSPrinterName sharename
$Sharename attributes +Shared'
$PrinterOnTS = "\\127.0.0.1\" + $ShareName
USE LPT1: $PrinterOnTS

Your users MUST BE power users otherwise the script WILL NOT WORK.

--
Cláudio Rodrigues, MVP
Windows 2000/NT Server
Terminal Services

http://www.terminal-services.NET

-> The only Terminal Services Client for DOS.
-> The only customized RDP5.1 client with the close button disabled! :-)
-> Developers of SecureRDP, the BEST security utility for TS!

Do NOT email me directly UNLESS YOU KNOW ME or you are a Microsoft
MVP/Employee.
Use my support page on my website to submit your questions directly.

I would very much like to use Cláudio Rodrigues' scrip but I get an error
message that says:
"printer rundll command failed. You either entered and printer name that was
not correct or the specified printer is no longer connected to the server."
I can print from DOS just fine when I open a command prompt window and type
NET USE LPT1: \\YOUR_TS_NAME\THE_SHARE_NAME_YOU_GAVE.
But, I'd really like to automate the process. I know it's something simple.
I guess I'm missing something.

Do I need to edit the script? If so, can anyone tell me specifically what
parts of this script I should edit? Perhaps I need to specify my printer
name or share name by substituting them in the script below? I've numbed the
lines to make it easier to reference them.

Thanks,
Steve Smith

rem get the session ID out of the %TEMP% environment variable
1. for /f "eol=; tokens=6 delims=\ " %%i in ("%TEMP%") do set TSSID=%%i
rem construct the printer name
2. set TSPrinterName=PrinterName/%CLIENTNAME%/Session %TSSID%
rem share the printer
3. rundll32 printui.dll,PrintUIEntry /Xs /n "%TSPrinterName%" sharename
"TSPrinter%TSSID%" attributes +Shared
4. net use lpt1: /DELETE
5 net use lpt1: \\127.0.0.1\TSPrinter%TSSID%
 
Cláudio Rodrigues wrote
Use this script......

Thanks again Cláudio. Please excuse my ignorance, I'm new to Terminal Server and I'm not familiar with scripting either. I need a little help in getting this script to run. Not knowing what I'm doing, I'm guessing and apparently I'm doing something wrong. I created a text file that contains your script and I named it printdos.cmd. Is this the correct way to make an executable script? I placed the printdos.cmd on the server, connected to the server from the TS client, ran the printdos.cmd file from the command prompt to test it. The ";" were not recognized as "rem" and those lines attempted to run. I then replaced each ";" with "rem" and tried again. Is there another way to run the script without the need to do this?

After rem-ing out the ";'" I still get several "not recognized as an internal or external command" error messages. I suspect some(or maybe all) of these errors are due to line wrapping in the post of your script and partial lines are attempting to run. I don't understand enough about the commands in the script to determine the correct place for the line break. Could you seperate the indivudial lines of the script by a blank line or place a "<LB>" at the end of each line? I'd really appreciate it. Am I doing anything else wrong? I've pasted the screen output that results from running the script below.

Thank you,
Steve Smith


C:\Documents and Settings\Steve\Desktop>printdos

C:\Documents and Settings\Steve\Desktop>REM Get the default printer name and s
re/map it for DOS apps.

C:\Documents and Settings\Steve\Desktop>REM By Clßudio Rodrigues, http://www.T
minal-Services.NET

C:\Documents and Settings\Steve\Desktop>REM Example String: HP LaserJet 4Si/CL
DIOXP/Session 1,winspool,TS002

C:\Documents and Settings\Steve\Desktop>REM Reads the default printer from the
egistry.

C:\Documents and Settings\Steve\Desktop>$DefaultPrinter = ReadValue("HKEY_CURR
T_USER\Software\Microsoft\Windows
'$DefaultPrinter' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>NT\CurrentVersion\Windows","Device")
The system cannot find the path specified.

C:\Documents and Settings\Steve\Desktop>REM Extracts the printer name on the T
Example: HP LaserJet

C:\Documents and Settings\Steve\Desktop>4Si/CLAUDIOXP/Session 1
'4Si' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$WhereisComma = InStr("$DefaultPrinter
",") - 1
'$WhereisComma' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$TSPrinterName = Left("$DefaultPrinter
"$WhereisComma")
'$TSPrinterName' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>REM Extracts the machine name/Session
.. Example: CLAUDIOXP/Session 1

C:\Documents and Settings\Steve\Desktop>$WhereisSlash = InStr("$TSPrinterName"
/") - 1
'$WhereisSlash' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$MachineAndSSID = Left("$DefaultPrinte
,"$WhereisSlash")
'$MachineAndSSID' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>REM Extracts the Session ID only from
e string above. Example: 1

C:\Documents and Settings\Steve\Desktop>$PosTemp = InStr("$TSPrinterName","/")
'$PosTemp' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$EndTemp = Len("$TSPrinterName") - $Po
emp
'$EndTemp' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$TempStr = Right("$TSPrinterName","$En
emp")
'$TempStr' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$PosTemp = InStr("$TempStr","/")
'$PosTemp' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$EndTemp = Len("$TempStr") - $PosTemp
'$EndTemp' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$TempStr = Right("$TempStr","$EndTemp"

'$TempStr' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$Pos2 = InStr("$TempStr"," ")
'$Pos2' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$End3 = Len("$TempStr") - $Pos2
'$End3' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$SSID = Right("$TempStr","$End3")
'$SSID' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$ShareName = "TSPrinter" + $SSID
'$ShareName' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$TSPrinterName = chr(34) + $TSPrinterN
e + chr(34)
'$TSPrinterName' is not recognized as an internal or external command,
operable program or batch file.
< was unexpected at this time.
C:\Documents and Settings\Steve\Desktop>If Len($LocalPrinter) <> 0
C:\Documents and Settings\Steve\Desktop>
 
This is a KIX32 script. Save it as PrintDOS.kix.
Go to http://www.kixtart.org and download KIX32. The only file you need is
KIX32.EXE.
Copy both files (PrintDOS.kix and KIX32.exe) to WINNT\SYSTEM32.
Edit WINNT\SYSTEM32\USRLOGON.CMD and at the end add a line:
KIX32.EXE PrintDOS.kix

This will do it.

--
Cláudio Rodrigues, MVP
Windows 2000/NT Server
Terminal Services

http://www.terminal-services.NET

-> The only Terminal Services Client for DOS.
-> The only customized RDP5.1 client with the close button disabled! :-)
-> Developers of SecureRDP, the BEST security utility for TS!

Do NOT email me directly UNLESS YOU KNOW ME or you are a Microsoft
MVP/Employee.
Use my support page on my website to submit your questions directly.

Cláudio Rodrigues wrote
Use this script......

Thanks again Cláudio. Please excuse my ignorance, I'm new to Terminal Server
and I'm not familiar with scripting either. I need a little help in getting
this script to run. Not knowing what I'm doing, I'm guessing and apparently
I'm doing something wrong. I created a text file that contains your script
and I named it printdos.cmd. Is this the correct way to make an executable
script? I placed the printdos.cmd on the server, connected to the server
from the TS client, ran the printdos.cmd file from the command prompt to
test it. The ";" were not recognized as "rem" and those lines attempted to
run. I then replaced each ";" with "rem" and tried again. Is there another
way to run the script without the need to do this?

After rem-ing out the ";'" I still get several "not recognized as an
internal or external command" error messages. I suspect some(or maybe all)
of these errors are due to line wrapping in the post of your script and
partial lines are attempting to run. I don't understand enough about the
commands in the script to determine the correct place for the line break.
Could you seperate the indivudial lines of the script by a blank line or
place a "<LB>" at the end of each line? I'd really appreciate it. Am I doing
anything else wrong? I've pasted the screen output that results from running
the script below.

Thank you,
Steve Smith


C:\Documents and Settings\Steve\Desktop>printdos

C:\Documents and Settings\Steve\Desktop>REM Get the default printer name and
s
re/map it for DOS apps.

C:\Documents and Settings\Steve\Desktop>REM By Clßudio Rodrigues,
http://www.T
minal-Services.NET

C:\Documents and Settings\Steve\Desktop>REM Example String: HP LaserJet
4Si/CL
DIOXP/Session 1,winspool,TS002

C:\Documents and Settings\Steve\Desktop>REM Reads the default printer from
the
egistry.

C:\Documents and Settings\Steve\Desktop>$DefaultPrinter =
ReadValue("HKEY_CURR
T_USER\Software\Microsoft\Windows
'$DefaultPrinter' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>NT\CurrentVersion\Windows","Device")
The system cannot find the path specified.

C:\Documents and Settings\Steve\Desktop>REM Extracts the printer name on the
T
Example: HP LaserJet

C:\Documents and Settings\Steve\Desktop>4Si/CLAUDIOXP/Session 1
'4Si' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$WhereisComma =
InStr("$DefaultPrinter
",") - 1
'$WhereisComma' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$TSPrinterName =
Left("$DefaultPrinter
"$WhereisComma")
'$TSPrinterName' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>REM Extracts the machine
name/Session
.. Example: CLAUDIOXP/Session 1

C:\Documents and Settings\Steve\Desktop>$WhereisSlash =
InStr("$TSPrinterName"
/") - 1
'$WhereisSlash' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$MachineAndSSID =
Left("$DefaultPrinte
,"$WhereisSlash")
'$MachineAndSSID' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>REM Extracts the Session ID only
from
e string above. Example: 1

C:\Documents and Settings\Steve\Desktop>$PosTemp =
InStr("$TSPrinterName","/")
'$PosTemp' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$EndTemp = Len("$TSPrinterName") -
$Po
emp
'$EndTemp' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$TempStr =
Right("$TSPrinterName","$En
emp")
'$TempStr' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$PosTemp = InStr("$TempStr","/")
'$PosTemp' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$EndTemp = Len("$TempStr") -
$PosTemp
'$EndTemp' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$TempStr =
Right("$TempStr","$EndTemp"

'$TempStr' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$Pos2 = InStr("$TempStr"," ")
'$Pos2' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$End3 = Len("$TempStr") - $Pos2
'$End3' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$SSID = Right("$TempStr","$End3")
'$SSID' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$ShareName = "TSPrinter" + $SSID
'$ShareName' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\Steve\Desktop>$TSPrinterName = chr(34) +
$TSPrinterN
e + chr(34)
'$TSPrinterName' is not recognized as an internal or external command,
operable program or batch file.
< was unexpected at this time.
C:\Documents and Settings\Steve\Desktop>If Len($LocalPrinter) <> 0
C:\Documents and Settings\Steve\Desktop>
 
Cláudio Rodrigues wrote
This is a KIX32 script....

Thanks, that helps a lot. I followed your instructions and unfortunately I still could not print from DOS. To troubleshoot, I ran the script form the command line and I tracked a couple of errors to the line wrapping. I fixed those but now I get this error message:

Printer rundll command failed:
Command: /Xs /n ""sharename
TSPrinter attributes +shared. Operation could not be completed.

Any ideas? I am logged on as an Administrator.

Thanks,
Steve Smith
 
Pay attention...
It is a SINGLE LINE between the two '.
NOT TWO LINES. The line wrapped.
All this is a SINGLE LINE:
Shell 'rundll32 printui.dll,PrintUIEntry /Xs /n $TSPrinterName sharename
$Sharename attributes +Shared'

--
Cláudio Rodrigues, MVP
Windows 2000/NT Server
Terminal Services

http://www.terminal-services.NET

-> The only Terminal Services Client for DOS.
-> The only customized RDP5.1 client with the close button disabled! :-)
-> Developers of SecureRDP, the BEST security utility for TS!

Do NOT email me directly UNLESS YOU KNOW ME or you are a Microsoft
MVP/Employee.
Use my support page on my website to submit your questions directly.

Cláudio Rodrigues wrote
This is a KIX32 script....

Thanks, that helps a lot. I followed your instructions and unfortunately I
still could not print from DOS. To troubleshoot, I ran the script form the
command line and I tracked a couple of errors to the line wrapping. I fixed
those but now I get this error message:

Printer rundll command failed:
Command: /Xs /n ""sharename
TSPrinter attributes +shared. Operation could not be completed.

Any ideas? I am logged on as an Administrator.

Thanks,
Steve Smith
 
Cláudio Rodrigues wrote
...All this is a SINGLE LINE:
Shell 'rundll32 printui.dll,PrintUIEntry /Xs /n $TSPrinterName sharename
$Sharename attributes +Shared'

I have this as a single line but I still get this error:

Printer rundll command failed.
Command: /Xs /n ""sharename
TSPrinter attributes +shared. Operation could not be completed.

Perhaps there is a problem elsewhere. I've posted the exact script that I'm using to http://members.cox.net/stevensmith/printdos.kix

I don't want to overuse your generosity, but I hope you will take a quick look at this to see if you can spot the problem.

Thanks again.
Steve Smith
 
Steve said:
Perhaps there is a problem elsewhere. I've posted the exact script
that I'm using to http://members.cox.net/stevensmith/printdos.kix

Anybody else have any ideas? It appears to me that the $TSPrinterName variable is not getting filled. The error message has "" where this string should be. I am logged on as an Administrator, but is it possible that there is a policy in place that is preventing this script from running correctly? Any help would be appreciated.

Thanks,
Steve Smith
 
Hi. Ive been wondering how to solve printing DOS application from Terminal Server. I've found it useful, and solved my problem.


terminal [dot] servebeer [dot] com / download / printer.zip

Hope it helps.

Adi.
 
Back
Top