title: Get logged in username in NSIS installer when running as another user [admin]
body: <p>I created an NSIS installer that requires elevation and also installs some files in the users <code>AppData</code> directory. This works fine as long as the current user is an administrator. If the user is a limited user then they must run the installer as an administrator, passing the admin credentials to the installer. This all works great except for the fact that NSIS installs the files to the admin users <code>AppData</code> directory in this case. This is because I have been using the <code>$PROFILE</code> variable to determine where to install the files but <code>$PROFILE</code> returns the path to the user that is running the installer and not the user who is logged onto the system.</p>
  
  <p>So to be clear, if <code>User A</code> is a limited account and <code>User B</code> is the admin account, when I log into the computer with <code>User A</code> and run the installer, passing the credentials for <code>User B</code>, I can only ever get <code>User B</code>'s username from NSIS and therefore cannot install the necessary files for <code>User A</code>.</p>
  
  <p>I am currently using NSIS v2.49, which I haven't updated in over 2 years so I assume it is quite outdated. At the time of writing, the NSIS site on sourceforge has been down for a few days so it has been difficult to find a current copy of the software. I am open to upgrading to NSIS v3.x if anyone can point out how this may help solve this issue.</p>
  
  <p>Here is some very simple code demonstrating my problem. If you build this installer and run it on a limited users desktop it will demonstrate 3 different attemps to get the currently logged in username, but all 3 will bring back the name of the user that is running the installer instead:</p>
  
  <pre><code>Outfile Test.exe
  RequestExecutionLevel admin ;Require admin rights on NT6+ (When UAC is turned on)
  
  !include LogicLib.nsh
  
  Function .onInit
  UserInfo::GetAccountType
  pop $0
  ${If} $0 != "admin" ;Require admin rights on NT4+
      MessageBox mb_iconstop "Administrator rights required!"
      SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
      Quit
  ${EndIf}
  
  MessageBox MB_OK $PROFILE
  System::Call "advapi32::GetUserName(t .r0, *i ${NSIS_MAX_STRLEN} r1) i.r2"
  MessageBox MB_OK "User name Test 1: $0"
  ReadEnvStr $0 "USERNAME" 
  MessageBox MB_OK "User name Test 2: $0" 
  
  FunctionEnd
  
  Page instfiles
  
  Section
  SectionEnd
  </code></pre>
  
  <p>Is there no way that an NSIS installer can determine the logged in users username when running the installer as another user?</p>