0

So here's the dealio. I would like to create a simple batch file that'll create a log of each user that remotes in to a server. I know I can use

echo %username% > lastuser.log

but we all use the same username to log in to the server. I was wondering if it was possible to replace the "%username%" with some variable that'll return the physical computer that MSTSC is running on's name. I'd also like this to be a running list with the time of log in, but I can probably figure that out.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Jared
  • 878
  • 3
  • 11
  • 19

2 Answers2

2

I believe you're looking for %CLIENTNAME%.

Dan Ports
  • 1,421
  • 9
  • 7
  • Side challenge. How do I make it so it echo's a new entry in to the log file rather than overwriting it? – Jared Mar 13 '12 at 14:43
  • 1
    You'd want to use the >> operator, as in `echo %CLIENTNAME% >> lastuser.log`. See the list of [command redirection operators](http://technet.microsoft.com/en-us/library/bb490982.aspx). – Dan Ports Mar 13 '12 at 14:57
0

I'll assume you want to do this on the server machine. I don't have MSTSC running at the moment, so I can't check this exactly, but suppose when a user logs in, the server does a netstat to see which remote machines have connections using the server on the MSTSC port. Would that work?

Marc
  • 11,403
  • 2
  • 35
  • 45
  • Hrm, this didn't return anything. 'echo %netstat%' just returns 'netstat' – Jared Mar 13 '12 at 14:39
  • @Jared, netstat is a command. at the command prompt, just type `netstat`. `netstat /?` shows the command usage. – Marc Mar 13 '12 at 15:08