0

Facts

On a non admin Windows account:

Execute in a command prompt: echo %username% It will display the current user name.

Execute in a command prompt as administrator: echo %username% It will display the admin user name.

Question

How to get the current user name in a program/script running as administrator ?


A strange behavior:

In a command prompt running as administrator:

  • explorer %appdata% will open an explorer window in the AppData of the administrator.

  • start %appdata% will open an explorer windows in the AppData of the current user.

Alex Placet
  • 567
  • 7
  • 20
  • seems like running process as admin is always under the user:administrator.
    When you are doing start %appdata% you're opening a new process under a different user
    – omer727 Oct 06 '15 at 12:46
  • If you ``start`` a bat file: ``echo %appdata%`` it displays the administrator appdata directory too... – Alex Placet Oct 06 '15 at 12:57
  • Thx @HarryJohnston, it's not a real duplicate because it requires C++. But that will help me. – Alex Placet Oct 07 '15 at 09:31
  • 1
    My reasoning was that the question says "in a program/script". The proposed duplicate shows you how to do it in a program. (And there is no way to do it in a script, other than by running a program to do it for you.) – Harry Johnston Oct 07 '15 at 19:47

0 Answers0