Logging Windows 2003 Terminal Server Connections - Creating the Batch File and Why it’s Used
(Page 2 of 4 )
There is an application that you run on the command line called QUERY. This is what we use to obtain the list of currently logged in users. The tool can also be used to gather other information at the terminal server. Try running
C:query /?
from a command prompt to see the list of available arguments. In our case we are interested in the USER argument. If you run this it will give you a list of the currently logged in users, along with some other information.
What we are going to do is run the QUERY USER command, and return the results to a text file. We will then use the contents of the text file to update our database table. Open up notepad or your preferred text editor, and type in the following:
REM Batch file to save the list of logged in users to a text file
REM First delete the current file if it exists
del /q c:CurrentTSUsers.txt
REM Now use the QUERY tool to get a list of users and re-direct the output
REM to a text file
query user >>c:CurrentTSUsers.txt
Once you have this in your file, save it to the root of your c: drive and call it GetTSUserInfo.bat
If you are doing this work on a terminal server, you should be able to run this batch file and look in the c:CurrentUsers.txt file to see all the logged in users.
Next: Writing the Script >>
More BrainDump Articles
More By Luke Niland