Quick access to Terminal Services Info (Username,Client Name)

l3wp

Newcomer
Joined
Sep 26, 2005
Messages
1
A couple of nice goodies can be found in the environment variables on a Terminal Server. For instance:
CLIENTNAME = *Name of the currently connected computer*
HOMEPATH = *The current user's home directory*
SystemRoot = *Obvious*
TEMP = *The user's temp directory*
USERNAME = *Obvious*
SESSIONNAME = *The name of the current session ex. "RDP-Tcp#233"*

You can get at them using

System.Environment.ExpandEnvironmentVariable("%VarName%")

where VarName = the variable you want

Lew Parker
EarthVectors Inc.
 
you can use the IDictionaryEnumerator to itinerate through each entry, eg:

Visual Basic:
[size=2][color=#0000ff]Dim[/color][/size][size=2] arrVariables [/size][size=2][color=#0000ff]As[/color][/size][size=2] IDictionary = Environment.GetEnvironmentVariables()[/size]
[size=2]
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] arrEnumerator [/size][size=2][color=#0000ff]As[/color][/size][size=2] IDictionaryEnumerator = arrVariables.GetEnumerator[/size]
[size=2]
[/size][size=2][color=#0000ff]While[/color][/size][size=2] arrEnumerator.MoveNext [/size]
[size=2] 
[/size][size=2][color=#008000]    '/// Key ( eg: LOGONSERVER ) , Value ( eg: \\DEN-HOME ) ...[/color][/size]
[size=2][color=black][/color][/size] 
[size=2][color=black]    Console.WriteLine(arrEnumerator.Entry.Key & " : " & arrEnumerator.Entry.Value)[/color]
[/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]While[/color][/size]
[size=2][color=#0000ff]
[/color][/size]
 
Back
Top