I'm working through exercises in pen-testing and I ran into an slight problem. How do I tell what user I'm currently logged in as?

  • whoami - Doesn't work, box is too old (pre-vista)
  • echo %username% - Literally echos %username%, variables don't work.
  • set - Doesn't display username, and home directory is set to default user

All credit for the solution goes to a co-worker of mine.

> copy NUL temp.txt
> dir /Q temp.txt
02/08/2016  07:06 PM     0 HOST\SOME_USER     temp.txt

Really anything that will create a temp file, empty or otherwise, and then get the author of that file.

Simple, but something that's easy to overlook when the usual methods are ruled out of the equation.