Solved

Retrieve login, IP, and computer name of remote desktop

Posted on 2009-05-13
6
1,730 Views
Last Modified: 2013-11-21
How can I retrieve information about computers that are logging into Terminal Server?  I prefer to us VB6 in an exe to retrieve the data or implement a batch file. Is there any kind of log file that TS keeps that tracks remote sessions. What I am most interested in is the login name on the remote computer, the computer's IP address and name. Any other info that can be retrieved from a session would be great.
0
Comment
Question by:Mach1pro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 6

Expert Comment

by:Kentrix70
ID: 24390807
Loginname could be taken from the environment variable %username%
The name and ip-address of the host, is a little more complicated, but here is how to retrieve it in C# .NET.

http://community.citrix.com/display/xa/How+to+get+client+IP+address+and+client+hostname+using+Terminal+Services+API

I am not sure, how you would do it with VB6, as I prefer to use C# for my programming.
0
 
LVL 6

Author Comment

by:Mach1pro
ID: 24391385
That doesn't help me much. If I had a vb example that used the api, then that would probably work.
0
 
LVL 6

Accepted Solution

by:
Kentrix70 earned 300 total points
ID: 24393025
You can get the name of the client with %clientname%

I finally found some vbcode here

http://groups.google.com/group/microsoft.public.windowsnt.terminalserver.protocols.tcpip/browse_frm/thread/7595a72b22089c76

Hope this will help you.

/Kent.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 6

Author Closing Comment

by:Mach1pro
ID: 31581189
That works by manually entering the number of a session, but is there a way to constantly poll Terminal Server to see what sessions are open so that the process can be automated?
0
 
LVL 6

Expert Comment

by:Kentrix70
ID: 24394114
You can use the utility "envtscip" from

http://www.ctrl-alt-del.com.au/CAD_Utils.htm

This utility adds an environment variable to the user session,
when it is run by the user logging on.

The variable is called %clientip%

You can then create a startup script or program,
that logs %username%, %clientname% and %clientip% to a file
or a DB (Sql Server as an example).

In that way, you will always have an updated list with this information.

Every user logging on should run a batchfile to create the environment variable.
An example is provided in the download.

I modified this example a bit by adding logging to a textfile in the end of the script.
You could of course change that according to your needs.

Just make sure, whatever you do, to let the bach script creating the environment variable run first,
so that it is created. Then you can access it like any other environment variable.

@Echo Off
:: call the client ip utility that assigns the environment variable
call "%SystemRoot%\System32\envtscip.exe"
 
::Becasue this is run in usrlogon.cmd, the environment variable cannot be broadcast to the windows shell
::thus we use the old classic Terminal Server tool ACRegL to enforce the variable during the logon script
 
"%systemroot%\Application Compatibility Scripts\ACRegL.exe" "%TEMP%\getpaths.cmd" CLIENTIP "HKCU\Volatile Environment" "CLIENTIP" ""
If Not ErrorLevel 1 Goto Cont1
Echo.
Echo Unable to retrieve path.
Echo.
Goto Finish
 
:Cont1
Call "%TEMP%\getpaths.cmd"
Del "%TEMP%\getpaths.cmd" >Nul: 2>&1
 
::The environment variable %clientip% can now be used throughout this script
::To use the environment variable %clientip% within a session run ENVTSCIP.exe in the startup of the user's session
::or the RUN section of the registry
 
::just as a test echo the variable to the screen
 
rem echo %CLIENTIP%
 
:Finish
 
echo User: %username%,Computer: %clientname%,IP: %clientip% >> \\<server>\<share>\logconnections.txt

Open in new window

0
 
LVL 6

Author Comment

by:Mach1pro
ID: 24394745
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Group policy not applying 5 108
Trust relationship when doing server upgrades 3 61
Shared files and folders migration 2 67
Exchange password change on mobile 2 111
This is my 3rd article on SCCM in recent weeks, the 1st (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/Windows_Server_2008/A_4466-A-beginners-guide-to-installing-SCCM2007-on-Windows-2008-R2-Server.html) dealing with installat…
Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip Migration Tip #1 – Source Server Health can be found listed in my profile here: http:…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question