Page 1 of 1 1
Topic Options
#19272 - 2002-03-29 03:54 PM Session ID number
Marko Offline
Lurker

Registered: 2002-03-29
Posts: 1
How can I query the system for session ID number when a terminal services session is on. I need that number to writte a key in the server registry in order to identificate and configurate in the right way, by a script, a shared printer.
The key ends with the session number. Something like that:

HKEY_CURRENT_USER\Printers\DevModePerUser]

"HP LaserJet 4L/MARKO-001/Sesion 3" = hex:48,00,50,00,20,00,4c,00,61,00,73,00,65,\
00,72,00,4a,00,65,00,74,00,20,00,34,00,4c,00,2f,00,41,00,53,00,45,00,52,00,\2d,00,30,00……………………………………………………………………………

In each session this "\session x" change his value. That's is why I need capture the string value.
Anybody can help me?
Thank's a lot

Top
#19273 - 2002-03-29 04:19 PM Re: Session ID number
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Do you have this environment variable available in your client session (WINSTATIONNAME=ICA-tcp#136)?

Is the number after the # what your looking for? If so use instr and substr to extract it.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#19274 - 2002-03-30 05:43 AM Re: Session ID number
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Here is a solution to your ID issue.

There is a tool called "query" on Terminal Servers that can be exploited.
code:
 shell "%comspec% /c query session @userID 1>session.txt"
IF Open(1, "session.txt") = 0
$x = ReadLine(1)
$x = ReadLine(1)
$x = Ltrim(substr($x,instr($x, @UserID) + Len(@UserID)))
$ID = substr($x,1, instr($x, " ")-1)
? $ID
ENDIF



[ 30 March 2002, 05:46: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#19275 - 2002-04-01 05:25 AM Re: Session ID number
Anonymous
Unregistered


Howard,
Regarding the environment variable idea:

%WinstationName% is only for NT 4.0 TS
The variable was changed to %SessionName% in 2000 TS

In both flavors, the environment variable reports "Console" when you logon from the console. The environment variable's name is somewhat misleading. It is neither the Winstation name nor the Session name. It is actually a combination of the connection name, followed by a pound symbol and then the session ID.

%ClientName% will only be populated if client session (not console session).

The logic should follow:
code:
if @InWin=1
if '%SessionName%' or '%WinstationName%'
; some sort of Terminal Server
if '%ClientName%'
; remote client
else
; logged on from console
endif
else
; not a Terminal Server
endif
else
; Windows 9x
endif


Top
#19276 - 2002-04-01 05:49 AM Re: Session ID number
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I found a case on NT4 TS where the environment did NOT hold up. The session ID reported by the GUI Admin tool was different than what followed the # sign in the environment variable. That is why I then posted the query.exe solution.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 262 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.036 seconds in which 0.016 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org