-1

We have a VBScript that pulls the username from HKCU\Volatile Environment\USERNAME. This is great except when running the script as an admin. Then this value changes to the admin username.

Where/how can I get the ORIGINAL username that was logged in? I can't get it from HKEY_CURRENT_USER because the ADMIN account get swapped in from HKEY_USERS.

karel
  • 5,489
  • 46
  • 45
  • 50

1 Answers1

0

I found it. I KNEW that the registry had to be hiding the last logged in user somewhere!

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\ LastLoggedOnUser = ".\crewr"

Pull that string and just

replace( returnedRegString, ".\", "" ) 

and you're golden!

user692942
  • 16,398
  • 7
  • 76
  • 175