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
Solved

Terminal Server session logging

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Know what services you can and cannot, should and should not combine on your server.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 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