When I was coding C# to connect from Mac to a Windows 10 PC I found a failed connection. I tried again with Microsoft Remote Desktop Client and it said authorization failed. The only account on the PC is logged in with a Microsoft ID which was a LIVE ID before(eg. [email protected]).

I tried

[email protected]"

or the full name displayed in account list which is

A B ([email protected])"

or the user name of the account, also name of the user home folder

abc

None of them is working.

I managed to connect with a local account credential(regular account name with password) but I need to know how to automatically set the account name in application when the user only logged in with a Microsoft ID(with no offline account).

Any comment?

1

There are 1 best solutions below

0
HelloWorld On

I also required the same mapping from a Windows Service code and did the following:

Enumerated all users using the API NetUserEnum() with level 0 to get each username.

For each username called NetUserGetInfo() with level 24. It uses the structure _USER_INFO_24 to return its Internet Identity for the username.

If the usri24_internet_principal_name member of the structure matched with the given Microsoft Id then we have located the required username.

Note: Level 24 is available in Windows 8 and above. But can be easily used with previous SDK by simply defining the _USER_INFO_24 structure in the code.

For a code snippet please see my answer at: Get the local login name for the given Microsoft Account returned by NetWkstaUserEnum API on Windows 8 and above