I'm trying to make a script that keeps track of login/logout times of all thin-client users and writes them to a text file on the server. I will set up a task in Task Scheduler that runs a batch file which writes to a text file every time a user logs in/out. To write to a file at C:/ The script must be run as admin. This can be accomplished by selecting "Run with highest privileges" in task scheduler, and making sure it's run under an admin account.

However, I believe that when I use the %USERPROFILE% command, it will return the admin's username, not that of whoever just logged in/out. Is there a way to run the script with admin rights, but have some command to get the user that just logged in/out, triggering the task?