Solved

Retrieve login, IP, and computer name of remote desktop

Posted on 2009-05-13
6
1,717 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
  • 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Every system administrator encounters once in while in a problem where the solution seems to be a needle in haystack.  My needle was an anti-virus version causing problems with my Exchange server. I have an HP DL350 with Windows Server 2008 Stand…
Know what services you can and cannot, should and should not combine on your server.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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