Is there a way in MATLAB to get the user name of the user that started the session?
I am interested in solutions for Windows, Linux and Mac OSX. I imagine that if the solutions are platform-specific, both solutions can be integrated as follows:
if ispc
user_name = % method 1
elseif isunix
user_name = % method 2
elseif ismac
user_name = % method 3
end
In the box, type cmd and press Enter. The command prompt window will appear. Type whoami and press Enter. Your current user name will be displayed.
a] $USER – Current user name. b] $USERNAME – Current user name. c] id command – Print current user name. d] whoami command – Show current user name.
To quickly reveal the name of the logged in user from the GNOME desktop used on Ubuntu and many other Linux distributions, click the system menu in the top-right corner of your screen. The bottom entry in the drop-down menu is the user name.
Use the “cat” command to list all the users on the terminal to display all the user account details and passwords stored in the /etc/passwd file of the Linux system. As shown below, running this command will display the usernames, as well as some additional information.
How about using Java (works on all platforms supported by MATLAB):
user_name = java.lang.System.getProperty('user.name')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With