From: Harald Oehlmann on
Special Windows question a bit off-topic but maybee, someone knows.

( Background: Citrix or WTS (Windows Terminal Services) allow multiple
users from distant computers to get a windows environment (->remote
session) each. If they start programs, they are physically started on
the server computer. This is similar to the help stuff in windows,
where the current screen is displayed remotely. Here, we have multiple
independent screens )

Q1) May a TCL/Tk program detect if it is started within a remote
session ?

Q2) May a TCL/Tk program detect if it is started on a system with
remote sessions ?

Thank you for any help,
Harald
From: Larry W. Virden on
On Mar 26, 5:56 am, Harald Oehlmann <wortka...(a)yahoo.de> wrote:

>
> Q1) May a TCL/Tk program detect if it is started within a remote
> session ?

Only if Citrix or WTS has some function that provides that
information. It must either put something in the registry,
environment, or at the very least provide some kind of program that
one can run to dientify whether one is directly on a desktop, remoting
into another machine, or working in a hosted computing environment.


> Q2) May a TCL/Tk program detect if it is started on a system with
> remote sessions ?
>

Can you tell us how this question differs from the first? I assume
there is a difference, but don't remember the old WTS days well enough
to recall what the difference is.
From: Alexandre Ferrieux on
On Mar 26, 10:56 am, Harald Oehlmann <wortka...(a)yahoo.de> wrote:
> Special Windows question a bit off-topic but maybee, someone knows.
>
> ( Background: Citrix or WTS (Windows Terminal Services) allow multiple
> users from distant computers to get a windows environment (->remote
> session) each. If they start programs, they are physically started on
> the server computer. This is similar to the help stuff in windows,
> where the current screen is displayed remotely. Here, we have multiple
> independent screens )
>
> Q1) May a TCL/Tk program detect if it is started within a remote
> session ?
>
> Q2) May a TCL/Tk program detect if it is started on a system with
> remote sessions ?

Q1: just looked at environment variables on an rdesktop connection to
a WTS server. I notice two ones:

env(KIT) = WTS
env(SESSIONNAME) = RDP-Tcp#70

Dunno whether you can depend on them though :}

Q2: look at TWAPI, maybe the process manager API can detect the other
sessions' processes ? Ashok would know...

-Alex
From: APN on
On Mar 26, 6:26 pm, Alexandre Ferrieux <alexandre.ferri...(a)gmail.com>
wrote:
> On Mar 26, 10:56 am, Harald Oehlmann <wortka...(a)yahoo.de> wrote:
>
> > Special Windows question a bit off-topic but maybee, someone knows.
>
> > ( Background: Citrix or WTS (Windows Terminal Services) allow multiple
> > users from distant computers to get a windows environment (->remote
> > session) each. If they start programs, they are physically started on
> > the server computer. This is similar to the help stuff in windows,
> > where the current screen is displayed remotely. Here, we have multiple
> > independent screens )
>
> > Q1) May a TCL/Tk program detect if it is started within a remote
> > session ?
>
> > Q2) May a TCL/Tk program detect if it is started on a system with
> > remote sessions ?
>
> Q1: just looked at environment variables on an rdesktop connection to
> a WTS server. I notice two ones:
>
>     env(KIT)                    = WTS
>     env(SESSIONNAME)            = RDP-Tcp#70
>
> Dunno whether you can depend on them though :}
>
> Q2: look at TWAPI, maybe the process manager API can detect the other
> sessions' processes ? Ashok would know...
>
> -Alex

Using TWAPI,

Q1. The command

twapi::GetSystemMetrics 0x1000

will return 1 if current process is in a remote session, 0 if local
console. (0x1000 is SM_REMOTESESSION from the Windows headers).

Q2. The command

twapi::get_multiple_process_info [twapi::get_process_ids] -tssession

will return a keyed list mapping process ids to their terminal
sessions. HOWEVER, note XP fast user switching is also implemented
using terminal services so when you see multiple terminal sessions,
you need to identify which is remote and which is not (The solution in
Q1 only applies to the current process). Also, not sure this is an
ideal solution from a performance point of view. Lastly, it will most
likely need admin privs.

Alternatively, you could do

twapi::WTSEnumerateSessions NULL

which will return a list of terminal server sessions and the names for
the window stations for each but I'm not sure if the window station
name will let you distinguish between local and remote. If not, you
can try one more thing - for each terminal session id returned from
WTSEnumerateSessions, call the command

twapi::WTSQuerySessionInformation NULL $terminal_session_id 10

This returns the client name (10 -> WTSClientName #define from Windows
headers). If an empty string, I would assume it is a local session.

Caveats: do not have a terminal services environment, so cannot test.
Also, above applies to terminal services, not sure how Citrix works.

/Ashok
From: Harald Oehlmann on
Thank you all for the good and quick answers.

Regards,
Harald