newtonspls

Microsoft Account Username

7 posts in this topic

Hi,

I need to be able to get the full Microsoft account name of a user on Windows 10 or 8. AutoIt's macro for @Username returns the local account alias name but I need the Microsoft email name (user1@outlook.com, rather than user1 returned by @Username). I thought this would be any easy task, but no go. I've looked into using WMI, some of the API's but nothing so far that would give me the correct username.

Share this post


Link to post
Share on other sites



I guess it depends; Are you looking for a internet style address for a domain user account (i.e. user@domain.com) or are you looking to retrieve the the Email address property from an Active Directory user object?  

Share this post


Link to post
Share on other sites

@newtonspls In looking at my Windows 10 box, I see about a dozen spots where you can find this information in the registry. Have you tried this option?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

The use case I'm trying to solve for is I need to be able to capture the full Microsoft account name(not AD) - if used, without any user intervention of the current logged on user. Since the @Username macro only gives me the local account name I need to be able to query the PC using the local account name to find out if a matching email account name exists. When I do a search in the Registry for the local account name I didn't find any keys or entries that also had the email account name that I could use to verify this type of account was used. I did however find a DLL that does have all of this information available - username both local and email, account type, etc., but I having a problem with trying to call the DLL.The DLL is Netapi32.dll and the function is NetWkstaUserGetInfo. https://msdn.microsoft.com/en-us/library/windows/desktop/aa370670(v=vs.85).aspx

I haven't do a lot of work with calling DLL's from Autoit but from what I gather since this function returns values I need to first create a struc to hold the values. The typedef for the struc is LMSTR. I did some Googling for this but didn't find anything that would translate to the available AutoIt types.

Local $userInfo = DllStructCreate("uint wkui1_username;uint wkui1_logon_domain;uint wkui1_oth_domain;uint wkui1_logon_server")
Local $dllcall = DllCall("Netapi32.dll", "none", "NetWkstaUserGetInfo", "dword", 1, "ptr", DllStructGetPtr($userInfo))
ConsoleWrite("UserName: " & DllStructGetData($userInfo, "wkui1_username") & @LF)

When I run it Autoit just crashes. the type "uint" I know is wrong but I've tried other types with no avail.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I'm not familiar with that DLL call, but looking at the msdn article I don't see any reference to an email account on the return info.  Secondly...if you're just talking about a local account on a workstation there is nothing that dictates that the local user name has anything to do with a user's email address.  Perhaps in your particular instance this isn't the case but there's not enough info to understand the environment.  What is the end goal you are looking to accomplish by "obtaining" an email address for a logged in user?  Perhaps there is another way to accomplish your goal.

Edited by spudw2k

Share this post


Link to post
Share on other sites
On ‎14‎.‎1‎.‎2016‎. at 2:30 PM, newtonspls said:

The use case I'm trying to solve for is I need to be able to capture the full Microsoft account name(not AD) - if used, without any user intervention of the current logged on user. Since the @Username macro only gives me the local account name I need to be able to query the PC using the local account name to find out if a matching email account name exists. When I do a search in the Registry for the local account name I didn't find any keys or entries that also had the email account name that I could use to verify this type of account was used. I did however find a DLL that does have all of this information available - username both local and email, account type, etc., but I having a problem with trying to call the DLL.The DLL is Netapi32.dll and the function is NetWkstaUserGetInfo. https://msdn.microsoft.com/en-us/library/windows/desktop/aa370670(v=vs.85).aspx

I haven't do a lot of work with calling DLL's from Autoit but from what I gather since this function returns values I need to first create a struc to hold the values. The typedef for the struc is LMSTR. I did some Googling for this but didn't find anything that would translate to the available AutoIt types.

Local $userInfo = DllStructCreate("uint wkui1_username;uint wkui1_logon_domain;uint wkui1_oth_domain;uint wkui1_logon_server")
Local $dllcall = DllCall("Netapi32.dll", "none", "NetWkstaUserGetInfo", "dword", 1, "ptr", DllStructGetPtr($userInfo))
ConsoleWrite("UserName: " & DllStructGetData($userInfo, "wkui1_username") & @LF)

When I run it Autoit just crashes. the type "uint" I know is wrong but I've tried other types with no avail.

It should be something like this:

#include <WinApi.au3>

$aCall = DllCall("Netapi32.dll", "dword", "NetWkstaUserGetInfo", "ptr", 0, "dword", 1, "ptr*", 0)
If Not @error Then
    $tWKSTA_USER_INFO_1 = DllStructCreate("ptr wkui1_username;ptr wkui1_logon_domain;ptr wkui1_oth_domain;ptr wkui1_logon_server;", $aCall[3])

    $sUserName = DllStructGetData(DllStructCreate("wchar[" & _WinAPI_StringLenW(DllStructGetData($tWKSTA_USER_INFO_1, "wkui1_username")) & "]", DllStructGetData($tWKSTA_USER_INFO_1, "wkui1_username")), 1)
    $sLogonDomain = DllStructGetData(DllStructCreate("wchar[" & _WinAPI_StringLenW(DllStructGetData($tWKSTA_USER_INFO_1, "wkui1_logon_domain")) & "]", DllStructGetData($tWKSTA_USER_INFO_1, "wkui1_logon_domain")), 1)
    $sOthDomain = DllStructGetData(DllStructCreate("wchar[" & _WinAPI_StringLenW(DllStructGetData($tWKSTA_USER_INFO_1, "wkui1_oth_domain")) & "]", DllStructGetData($tWKSTA_USER_INFO_1, "wkui1_oth_domain")), 1)
    $sLogonServer = DllStructGetData(DllStructCreate("wchar[" & _WinAPI_StringLenW(DllStructGetData($tWKSTA_USER_INFO_1, "wkui1_logon_server")) & "]", DllStructGetData($tWKSTA_USER_INFO_1, "wkui1_logon_server")), 1)

    DllCall("Netapi32.dll", "dword", "NetApiBufferFree", "struct*", $tWKSTA_USER_INFO_1)

    ConsoleWrite("UserName: " & $sUserName & @CRLF)
    ConsoleWrite("LogonDomain: " & $sLogonDomain & @CRLF)
    ConsoleWrite("OthDomain: " & $sOthDomain & @CRLF)
    ConsoleWrite("LogonServer: " & $sLogonServer & @CRLF)
EndIf

 

1 person likes this

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now