newtonspls Posted January 12, 2016 Share Posted January 12, 2016 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. Link to comment Share on other sites More sharing options...
spudw2k Posted January 12, 2016 Share Posted January 12, 2016 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? Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 12, 2016 Moderators Share Posted January 12, 2016 @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? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
newtonspls Posted January 14, 2016 Author Share Posted January 14, 2016 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).aspxI 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. Link to comment Share on other sites More sharing options...
spudw2k Posted January 14, 2016 Share Posted January 14, 2016 (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 January 14, 2016 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
trancexx Posted January 16, 2016 Share Posted January 16, 2016 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 oneLess 1 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Administrators Jon Posted January 16, 2016 Administrators Share Posted January 16, 2016 This stackoverflow post has something where they were complaining that the api was returning the full account name. Might be useful. http://stackoverflow.com/questions/34306052/get-the-local-login-name-for-the-given-microsoft-account-returned-by-netwkstause Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now