How can Windows 10 user account info be accessed through Matlab

15 ビュー (過去 30 日間)
Robert Heaton
Robert Heaton 2022 年 2 月 9 日
回答済み: Robert Heaton 2022 年 2 月 16 日
Our IT is currently transitioning from name based user accounts to numbered accounts. We have Matlab scripts which we use to generate documents that include user identification. The script is used the command:
username = getenv('USERNAME')
to find this information; however, this command returns the numbered account rather than an identifiable name. A proper name has been associated to the numbered account as seen in the O/S account settings. Windows can also associate additional information such as a picture with the account. What command should be used to get this information from the environment or operating system that is associated with current user running a Matlab session?

採用された回答

Robert Heaton
Robert Heaton 2022 年 2 月 16 日
Found something that works -- needed to specify the network domain to get the information that I'm looking. The code below works, using a system pipe to select out the required data.
SearchPattern = 'Full Name';
[Result, FullName] = system(['net user "%USERNAME%" /domain | FIND /I "' SearchPattern '"']);
FullName = strtrim(strrep(FullName,SearchPattern,''));

その他の回答 (1 件)

Turlough Hughes
Turlough Hughes 2022 年 2 月 9 日
You could try system as follows:
[~,info] = system('whoami');
[~,info] = system('net user'); % another possibility
  3 件のコメント
Turlough Hughes
Turlough Hughes 2022 年 2 月 9 日
The system function runs O/S commands which is equivalent to doing it in command promt. I see what you mean now with the account settings username being different. I think the following should work (atleast it does on my computer):
[~,info] = system('wmic useraccount get FullName')
give it a try and let me know.
Robert Heaton
Robert Heaton 2022 年 2 月 9 日
Tried that command, but no success with this either. When I execute the command within Matlab, the system doesn't come back with a response. I also tried executing this in the MS command prompt window, with the same result. I did confirm in the command window that wmic executes; not sure why it would stall, although it's possible that it's waiting for more input.
I was also talking with a few other computer savvy people, and they suggested that the information I'm looking for is being managed by Active Directory, which I think means that I have to issue an LDAP query (found this on-line: https://ldapwiki.com/wiki/LDAP%20Query%20Examples ). I haven't had a chance to explore this, but I'm thinking that I may be able to execute a query to this through the Matlab system command.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by