How to get the account username using MATLAB?

405 次查看(过去 30 天)
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 个评论
Ramnath Natarajan
Ramnath Natarajan 2022-7-19
If u run command prompt (windows button + R ------> type 'cmd' and press 'Enter'), the default command line shows the username (image below)

请先登录,再进行评论。

采纳的回答

Chuck
Chuck 2016-2-21
编辑:Chuck 2016-2-21
Found it! :) It's extremely straight-forward.
Let me post it here for those who are struggling to find:
getenv('username')
  4 个评论
Walter Roberson
Walter Roberson 2019-3-29
Which operating system, Ram? The solution for Windows is likely to be quite different than Linux or Mac.
Walter Roberson
Walter Roberson 2019-3-29
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

请先登录,再进行评论。

更多回答(2 个)

Image Analyst
Image Analyst 2016-2-21
To get the folder, you can use
userProfile = getenv('USERPROFILE');
  2 个评论
Ashish Sheikh
Ashish Sheikh 2020-3-16
I guess this is for Windows .. Do you by chance know how to get the userprofile on linux and mac ?
Walter Roberson
Walter Roberson 2020-3-16
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

请先登录,再进行评论。


Eran
Eran 2022-1-20
编辑:Image Analyst 2022-7-19
userName = char(java.lang.System.getProperty('user.name'))
userName = 'mluser'
  4 个评论
Steven Lord
Steven Lord 2022-10-11
@Francisco Sacchetti What are you hoping or planning to do with that information in a web app?
Francisco Sacchetti
Francisco Sacchetti 2022-10-12
编辑:Francisco Sacchetti 2022-10-12
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Manage Products 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by