Solved

Terminal Server session logging

Posted on 2008-10-30
8
1,286 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Know what services you can and cannot, should and should not combine on your server.
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

9 Experts available now in Live!

Get 1:1 Help Now