Solved

Retrieve login, IP, and computer name of remote desktop

Posted on 2009-05-13
6
1,756 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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Remote Desktop Protocol or RDP has become an essential tool in many offices. This article will show you how to set up an external IP to point directly to an RDP session. There are many reasons why this is beneficial but perhaps the top reason is con…
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 here: http://www.experts-exchang…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

634 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