Docstoc

MAPPING DYNAMIC PRINTER

Document Sample
MAPPING DYNAMIC PRINTER Powered By Docstoc
					                                                                                                                      Page 1 of 3

CGS INTERNAL DOCUMENTATION
DOCUMENT # Mapping Dynamic Printer.DOC (located in \\CGS-TSERVER1\DATA\CGSDOCS)
SUBJECT : MAPPING DYNAMIC PRINTERS TO LPT PORTS IN TERMINAL SERVICES
DATE    : 07/10/03
VERSION : 1.0
SUMMARY OF PROBLEM
In Terminal Services Client Sessions, printers which are local to the client machine and shared, are available within the session
but with names which include the session number. Since the session number can change with each login, it is impossible to
write a static net use command.

ABSTRACT SOLUTION
In Terminal Services Client Sessions, the TEMP variable within the dos environment contains among other things the session
number. By parsing that session number out and storing in another dos environment variable called TSSID, we can use it to
generate a session-specific, current printer name which we store in another dos environment variable called
TSPRINTERNAME. Then a call to the PRINTUIENTRY function of the PRINTUI.DLL windows component can share that
session-specific current printer name to a fixed share name called MYPRN. MYPRN can then be used in one or more net use
commands to map the printer to an LPT port.

EXAMPLE INVBAT.CMD BATCH FILE WHICH USES THIS TECHNIQUE…

rem echo off
for /f "eol=; tokens=6 delims=\ " %%i in ("%TEMP%") do set TSSID=%%i
set TSPrinterName=testchit/%CLIENTNAME%/Session %TSSID%
rundll32 printui.dll,PrintUIEntry /Xs /n "%TSPrinterName%" sharename "myprn" attributes +Shared
net use lpt1: /DELETE
net use lpt1: \\192.168.1.11\myprn
echo on
pause
d:
cd\cgs\inv
invt /cg\golf

EXAMPLE EXPLAINED

The first active line is a dos for loop which parses out the session id from the TEMP dos environment variable and puts the
results in TSSID. This line can be used “AS IS” and does not need to be modified for different batch files, networks or
computers.

The second line creates a dos environment variable called TSPRINTERNAME by combining the name of the printer “testchit”
to a slash “/” to the currently logged in terminal server client (drawn from CLIENTNAME dos environment variable which is
automatically created by terminal services during login) to the fixed text “/Session “ and finally to the session id number which
we identified in line one. The result is the printer name just like it shows up in terminal server session’s start/settings/printers
dialog. (Notice the space after the word session.)

The third line is black magic windows internals stuff. Here the rundll32 utility is used to call part of the windows kernel
(printui.dll) to run its PrintUIEntry function which shares out the TSPRINTERNAME printer as a fixed share name (myprn in
this case). If for any reason, more than one printer is to be shared in this manner on any given network, each printer’s share
name MUST BE DIFFERENT AND UNIQUE.

The rest of this batch file is right out of standard installation techniques. Note that the second net use command which adds the
printer mapping is using the LOCAL IP ADDRESS of the terminal server. In theory, this comman would work using the
terminal server’s computer name instead.
Also, the pause command is only there to help you debug the batch file. Remove it once everything works and add an ECHO
OFF command before the first line to hide the complexities from the users.




DOCUMENT # Mapping Dynamic Printer.DOC             - located in \\CGS-TSERVER1\DATA\CGSDOCS
Printed On 4/24/11 4:35 AM
                                                                                                                      Page 2 of 3

USING THIS TECHNIQUE (A STEP BY STEP APPROACH)

1). Prior to starting the terminal session, go to the \start\settings\printers dialog box and share the printer. The share name is
unimportatnt since terminal services doesn’t use it for this kind of thing.

2). Log into terminal services.

3). From within terminal services, go to the \start\settings\printers dialog box and write down name of the printer (the one you
want to map to) as it appears in the main dialog box window (switch to detail view to make it easier to read). The name should
have a format such as…

printer-name/clientname/session #

where printer-name is the fixed name of the printer
   clientname is the login name which may change as you login under different ids.
   session is fixed text (notice the space between the “N” and the “#” sign (session number)
 and # is the dynamic and changing session number associated with this login.

Write printer name portion of this line down!

4). Edit the batch file which is used to call the CGS dos software that requires the mapped printer. Insert a blank line at the top
and add the following lines of text…

rem echo off
for /f "eol=; tokens=6 delims=\ " %%i in ("%TEMP%") do set TSSID=%%i
set TSPrinterName=PRINTERNAME/%CLIENTNAME%/Session %TSSID%
rundll32 printui.dll,PrintUIEntry /Xs /n "%TSPrinterName%" sharename "myprn" attributes +Shared
net use lpt1: /DELETE
net use lpt1: \\192.168.1.11\myprn
echo on
pause

Note the darkened PRINTERNAME and IP Address. These should be modified to…

PRINTERNAME is the printer name portion of the line you wrote down in step 3.
192.168.1.11 should be replaced with the local ip address of the terminal server or (in theory) with the computer name of the
terminal server.

5). Save your changes and run the batch file. It should report that the net use command completed successfully. If not, review
the text for a typo or incorrect printer name/ip address.

6). Once the batch file runs without problems, remove the PAUSE command and insert an ECHO OFF before the first line of
the batch file.

7). Enjoy.


THE FINAL PRODUCT SHOULD RESEMBLE…
echo off
for /f "eol=; tokens=6 delims=\ " %%i in ("%TEMP%") do set TSSID=%%i
set TSPrinterName=HPLASER4/%CLIENTNAME%/Session %TSSID%
rundll32 printui.dll,PrintUIEntry /Xs /n "%TSPrinterName%" sharename "myprn" attributes +Shared
net use lpt1: /DELETE
net use lpt1: \\192.168.1.2\myprn
echo on
rem pause
d:
cd\cgs\ar
arnew /hd:\cgs\ar\




DOCUMENT # Mapping Dynamic Printer.DOC             - located in \\CGS-TSERVER1\DATA\CGSDOCS
Printed On 4/24/11 4:35 AM
                                                                                                          Page 3 of 3

ADDENDUM – FOR MORE THAN ONE PRINTER MAPPING ON A SINGLE MACHINE

Case Study : Gadmin1 is an administrative workstation with a laser printer HPLASERJ and a barcode printer BLASTER
attached to it. Both are shared and the user logs in as GA1. The batch file would look like…
echo off
for /f "eol=; tokens=6 delims=\ " %%i in ("%TEMP%") do set TSSID=%%i
set TSPrinterName=HPLASERJ/%CLIENTNAME%/Session %TSSID%
rundll32 printui.dll,PrintUIEntry /Xs /n "%TSPrinterName%" sharename "myrptprn" attributes +Shared
set TSBlasterName=BLASTER/%CLIENTNAME%/Session %TSSID%
rundll32 printui.dll,PrintUIEntry /Xs /n "%TSBlasterName%" sharename "mylblprn" attributes +Shared
net use lpt2: /DELETE
net use lpt2: \\192.168.1.2\myrptprn
net use lpt3: /DELETE
net use lpt3: \\192.168.1.2\mylblprn
echo on
rem pause
d:
cd\cgs\inv
invt /cd:\cgs\inv\ga1\golf


Notice that were are using two printer name variables TSPRINTERNAME and TSBLASTERNAME, two sharenames
MYRPTPRN and MYLBLPRN and two sets of net use commands each with a different port number. Also notice that we only
have to parse the session number out once (in the first line) because it will be the same for both printers.




DOCUMENT # Mapping Dynamic Printer.DOC        - located in \\CGS-TSERVER1\DATA\CGSDOCS
Printed On 4/24/11 4:35 AM

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:11
posted:4/24/2011
language:Basque
pages:3