Get the current user email using Active DirectoryTag(s): WinAPI/Registry


OLEObject ole_wsh
string ls_email

ole_wsh = CREATE OLEObject
ole_wsh.ConnectToNewObject("MSScriptControl.ScriptControl")
ole_wsh.Language = "vbscript"
ole_wsh.AddCode('Function getEmail()~r~n' &
+ 'Dim objADSysInfo~r~n'  &
+ 'Set objADSysInfo = CreateObject("ADSystemInfo")~r~n'  &
+ 'Dim objUser~r~n' &
+ 'Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)~r~n' &
+ 'getEmail = objUser.Mail~r~n' &
+ 'End Function')

ls_email = ole_wsh.Eval("getEmail")
ole_wsh.DisconnectObject()
DESTROY ole_wsh

MessageBox("Your email",ls_email)

blog comments powered by Disqus