I need to be able to get the username (or profile path) of the currently logged on user from my app which may be running either as admin or a service running under system account
I have tried all the various methods mentioned found on google to varying degrees of success, but none of them work in all circumstances e.g. WMI "SELECT UserName FROM Win32_ComputerSystem" doesn't work if running in RDP, or WMI get owner of a process such as explorer.exe is too slow.
I have also tried looking in registry, but a lot of the locations where path / name is shown e.g. HKEY_CURRENT_USER\Volatile Environment is then not available when accessing registry as admin or system, it only shows when accessing it as the user.
Any ideas please?