Borrar filtros
Borrar filtros

How to get the account username using MATLAB?

400 visualizaciones (últimos 30 días)
Chuck
Chuck el 21 de Feb. de 2016
Editada: Francisco Sacchetti el 12 de Oct. de 2022
I am talking about the username, not the host or computer name. For instance, if you are working on Google Drive, your Drive folder will be under C://users/USERNAME. I am talking about that USERNAME part. :)
  1 comentario
Ramnath Natarajan
Ramnath Natarajan el 19 de Jul. de 2022
If u run command prompt (windows button + R ------> type 'cmd' and press 'Enter'), the default command line shows the username (image below)

Iniciar sesión para comentar.

Respuesta aceptada

Chuck
Chuck el 21 de Feb. de 2016
Editada: Chuck el 21 de Feb. de 2016
Found it! :) It's extremely straight-forward.
Let me post it here for those who are struggling to find:
getenv('username')
  4 comentarios
Walter Roberson
Walter Roberson el 29 de Mzo. de 2019
Which operating system, Ram? The solution for Windows is likely to be quite different than Linux or Mac.
Walter Roberson
Walter Roberson el 29 de Mzo. de 2019
Note that the solutions might be different for network login situations.
For Mac it looks like you could use
[status, fullname] = system('id -F')
but watch out as it will include line terminator

Iniciar sesión para comentar.

Más respuestas (2)

Image Analyst
Image Analyst el 21 de Feb. de 2016
To get the folder, you can use
userProfile = getenv('USERPROFILE');
  2 comentarios
Ashish Sheikh
Ashish Sheikh el 16 de Mzo. de 2020
I guess this is for Windows .. Do you by chance know how to get the userprofile on linux and mac ?
Walter Roberson
Walter Roberson el 16 de Mzo. de 2020
Mac and Linux do not have user profile. See https://www.mathworks.com/matlabcentral/answers/269214-how-to-get-the-account-username-using-matlab#comment_344298

Iniciar sesión para comentar.


Eran
Eran el 20 de En. de 2022
Editada: Image Analyst el 19 de Jul. de 2022
userName = char(java.lang.System.getProperty('user.name'))
userName = 'mluser'
  4 comentarios
Steven Lord
Steven Lord el 11 de Oct. de 2022
@Francisco Sacchetti What are you hoping or planning to do with that information in a web app?
Francisco Sacchetti
Francisco Sacchetti el 12 de Oct. de 2022
Editada: Francisco Sacchetti el 12 de Oct. de 2022
I found a path:
  • Enable SSL on the server. For more information, see Enable SSL.
  • Enable authentication on the server. For more information, see Authentication.
And then you can use compiler.UserInfo() to get the infromation of the user.
I want to first to track who is using the app, also it will be nice to adapt the app depending on the users.

Iniciar sesión para comentar.

Categorías

Más información sobre Manage Products en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by