Solved

Terminal Server session logging

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

770 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