Hi,
I’m having trouble in getting the current user’s username, I’m running the console app in bash terminal with sudo.
If I run the console app directly without the need to use bash I can get the username just fine. But if I run the console app in a bash terminal it gives me a different path.
Without bash, my path is /home/Pi/Desktop (which is what I wanted)
With bash, my path is /root/Desktop
I tried to do the SpecialFolders.Userhome
and System.EnvironmentVariable("USER")
both return “root” if I use bash.
But if I don’t use bash, it returns ‘Pi’
Any help would be appreciated, thank you.
Would this work?
[code]dim oShell as new Shell
oShell.Execute(“whoami”)
dim sUsername as String = oShell.ReadAll
[/code]
Edit: Looks like if you run it with sudo, you get root as the username.
Edit 2: With five minutes of googling, I found this answer that seems to work: https://stackoverflow.com/a/4597929/6047977
Thanks Tim, I’ll let you know if it works once I get to the office.
Edit: Thanks Tim, System.EnvironmentVariable("SUDO_USER")
worked perfectly!
SystemInformationMBS module also provides a UserName function if you use MBS Plugin.
Thanks for the info @Christian, I did try MBS first and yes it showed me the correct username. 