Printing in TS (was RE: Telnet with a Windows 2003 server) (fwd)

Bob Rasmussen ras at anzio.com
Mon Dec 3 09:23:45 PST 2007


In response to a request, I have added two more pieces of information that 
can be returned by my RemoteInfo program, both related to the default 
printer. 

remoteinfo 101
   returns the Windows default printer name, as reported by Windows. In my 
   setup, for instance, it returns 
     Lexmark Optra R Plus Series (from BOB820) in session 1

remoteinfo 102
   returns the same except it removes the " (from whatever)"

If you capture this into an environment variable, then a script can 
determine what your default printer would be, and react to that.

For more details see the previous message below.

Regards,
....Bob Rasmussen,   President,   Rasmussen Software, Inc.

personal e-mail: ras at anzio.com
 company e-mail: rsi at anzio.com
          voice: (US) 503-624-0360 (9:00-6:00 Pacific Time)
            fax: (US) 503-624-0760
            web: http://www.anzio.com

---------- Forwarded message ----------
Date: Thu, 29 Nov 2007 11:20:07 -0800 (PST)
From: Bob Rasmussen <ras at anzio.com>
To: filePro Mailing List <filepro-list at lists.celestial.com>
Subject: Printing in TS (was RE: Telnet with a Windows 2003 server)

First, thanks to Ken for pointing me in the right direction, indirectly. 
It turns out that a variation of the FOR command can read output (stdout) 
from a command-line program, and copy it into a variable, similar to the 
Unix
   var=`somecommand`

To recap the problem I'm trying to solve: I want a program (such as 
filePro) running on a Terminal Services server to print on a specific 
printer attached to my client PC (running Remote Desktop Client). The 
problem is that the visible name of the printer from the server's point of 
view changes with the session number.

So here, I think, is a way to identify the name of a client-connected 
printer, when in a Terminal Services (TS) environment:

1) I created a program called remoteinfo.exe, which is available here:
      http://www.anzio.com/~ras/remoteinfo.exe
This program takes a single numeric parameter, which indicates which piece 
of information to return about the "remote" environment. (Internally, it 
uses WTSQuerySessionInformation.) Those parameters will be obvious below. 

Grab this program and put it on your server. It's not an installer, just a 
program.

2) Put the following into a file named "getremotevars.bat":
rem Get remote variables using RemoteInfo.exe
for /F %%i in ('remoteinfo.exe 1') do set REMOTE_SESSION=%%i
for /F %%i in ('remoteinfo.exe 2') do set REMOTE_IP=%%i
for /F %%i in ('remoteinfo.exe 3') do set REMOTE_MACHINE=%%i
for /F %%i in ('remoteinfo.exe 4') do set REMOTE_STATION=%%i
set REMOTE_PRINT=(from %REMOTE_MACHINE%) in session %REMOTE_SESSION%

3) From a TS session, run this BAT. It will put into your environment five 
variables starting with REMOTE. You can look at these with "set". The 
important one is REMOTE_PRINT, which gives a suffix for your printer name. 
In my case, for instance, "set" reveals
   REMOTE_PRINT=(from BOB820) in session 1

4) Now suppose I want to print on the printer named "lexmark" on my client 
PC. I need to construct a name from "lexmark", a space, then the contents 
of REMOTE_PRINT. For instance, to tell printwiz.exe to print on my 
printer, I include a parameter:
       /p"Lexmark %REMOTE_PRINT%"

It works!

I welcome your comments.

Regards,
....Bob Rasmussen,   President,   Rasmussen Software, Inc.

personal e-mail: ras at anzio.com
 company e-mail: rsi at anzio.com
          voice: (US) 503-624-0360 (9:00-6:00 Pacific Time)
            fax: (US) 503-624-0760
            web: http://www.anzio.com


More information about the Filepro-list mailing list