Jump to content
Xtreme .Net Talk

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


Recommended Posts

Posted

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.

  • Leaders
Posted

you can use the IDictionaryEnumerator to itinerate through each entry, eg:

 

[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]

  • 5 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...