How to get the account username using MATLAB?
283 ビュー (過去 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
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
2016 年 2 月 21 日
編集済み: Chuck
2016 年 2 月 21 日
4 件のコメント
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
2019 年 3 月 29 日
Some of the techniques for Windows are described at https://stackoverflow.com/questions/7809648/get-display-name-of-current-windows-domain-user-from-a-command-prompt
Note that the solutions might be different for network login situations.
See also the .net approach https://www.codeproject.com/Articles/42282/Get-a-User-s-Full-Name
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
2016 年 2 月 21 日
To get the folder, you can use
userProfile = getenv('USERPROFILE');
2 件のコメント
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
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
2022 年 1 月 20 日
編集済み: Image Analyst
2022 年 7 月 19 日
userName = char(java.lang.System.getProperty('user.name'))
4 件のコメント
Steven Lord
2022 年 10 月 11 日
@Francisco Sacchetti What are you hoping or planning to do with that information in a web app?
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 Center および File Exchange で Web Services についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!