Solved

Terminal Server session logging

Posted on 2008-10-30
8
1,300 Views
Last Modified: 2013-11-21
I'm using the instructions from http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/2003_Server/Q_23202062.html?sfQueryTermInfo=1+%22comput+name%22+connect+log+server+termin to create a batch file to log when users log on to my terminal server.

I'd like to also log the CLIENT NAME as displayed in Terminal Services Manager.  I've discovered the command QWINSTA to display session stats, but the 'DEVICE' field is always blank. Is there a way to get this command to display the client name/device? If not, what other way could I go about it?
0
Comment
Question by:menreeq
  • 3
  • 2
8 Comments
 
LVL 77

Expert Comment

by:Rob Williams
ID: 22921104
I (writer of the script) am not sure what you mean by "CLIENT NAME". The script logs the computer name as well as the user/client name, as it is now. Perhaps if you can clarify we can add the necessary information.

There is the "sessionname" command that gives you the same information plus the temporary session name, but I cannot see logging that as being of much use:
http://msmvps.com/blogs/robwill/archive/2008/06/12/determine-if-the-terminal-server-console-session-is-in-use-from-a-command-line.aspx
0
 

Accepted Solution

by:
menreeq earned 0 total points
ID: 22935907
I was able to find an app called 'envtscip' to assist me with this. my code is posted below.
@Echo Off

:: call the client ip utility that assigns the environment variable

call "\\server\netlogon\envtscip.exe"

If ErrorLevel 1 set clientname = null
 

::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
 

:Finish
 

for /f "Tokens=2 Delims=[]" %%i in ('ping -n 1 "%computername%"') do set IP=%%i

echo Username: , %username% , RemoteIP: , %CLIENTIP% , RemoteName: , %CLIENTNAME% , Computername: , %computername% , LocalIP: , %ip% , %date% , %time% >> \\server\log\logon.csv

echo Username: , %username% , RemoteIP: , %CLIENTIP% , RemoteName: , %CLIENTNAME% , Computername: , %computername% , LocalIP: , %ip% , %date% , %time%

Open in new window

0
 

Author Comment

by:menreeq
ID: 22935916
Thanks for your response RobWill.  

"CLIENT NAME as displayed in Terminal Services Manager"

this is the connecting computer's computername, if you look in my code above, you'll see that I found an application/environment variable to suit my need.
0
 
LVL 77

Expert Comment

by:Rob Williams
ID: 22936326
Sounds good. Glad you were able to find a solution.
Where this will be readable for eternity, it would be nice to give Warren Simondson of www.ctrl-alt-del.com.au credit for the script.

Cheers !
--Rob
0
 
LVL 77

Expert Comment

by:Rob Williams
ID: 22949887
Never met an Australian I didn't like, and as you say, they have some great minds waaaay down there.
--Rob
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now