I would like to know which user is logged in to Windows from the bat script I launch with right click and "Run as Administrator". If I try echo %username%
the script obviously output "Administrator"
Is there a way to know which user launched a cmd command as administrator?
How to reproduce:
- Log in to Windows with a normal user (in my case "test_user")
- Launch a
.bat
as administrator (right click and choose "run as administrator")
If in the .bat
file there is the environment variables %username%
it is going to be translated in "Administrator" instead of "test_user"
How can I know which user launched the .bat
file as "administrator"?