VB script to read Current user first name, last name and contact number from outlook ?
VB script to read Current user first name, last name and contact number from outlook ?
0 Comments
[ + ] Show comments
Answers (7)
Please log in to answer
Posted by:
spartacus
18 years ago
I assume you mean you wish to read this from the contacts list .... ?
If so, the following should help get you started - it's an extract from a Technet article, so I can't claim any credit, myself [;)]
[font="Courier New"]On Error Resume Next
Const olFolderContacts = 10
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set colContacts = objNamespace.GetDefaultFolder(olFolderContacts).Items
For Each objContact In colContacts
Wscript.Echo objContact.FullName, objContact.BusinessTelephoneNumber
Next
Regards,
Spartacus
If so, the following should help get you started - it's an extract from a Technet article, so I can't claim any credit, myself [;)]
[font="Courier New"]On Error Resume Next
Const olFolderContacts = 10
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set colContacts = objNamespace.GetDefaultFolder(olFolderContacts).Items
For Each objContact In colContacts
Wscript.Echo objContact.FullName, objContact.BusinessTelephoneNumber
Next
Regards,
Spartacus
Posted by:
gmorgan618
18 years ago
if you need the first and last name seperated...
arrName = Split(objContact.FullName, " ") 'Change the " " to the actual delimiter which might be ", "(comma space) - I'm not sure how names are extracted --> this will return an array split by the delimiter so ...
strFirstName = arrName(0)
strLastName = arrName(1)
Hopefully you get the idea. if the user had a first middel and last name like Joe williams bob then
strFirstName = arrName(0)
strMiddleName = arrName(1)
strLastName = arrName(2)
Good Luck
arrName = Split(objContact.FullName, " ") 'Change the " " to the actual delimiter which might be ", "(comma space) - I'm not sure how names are extracted --> this will return an array split by the delimiter so ...
strFirstName = arrName(0)
strLastName = arrName(1)
Hopefully you get the idea. if the user had a first middel and last name like Joe williams bob then
strFirstName = arrName(0)
strMiddleName = arrName(1)
strLastName = arrName(2)
Good Luck
Posted by:
spartacus
18 years ago
Posted by:
skj
18 years ago
Posted by:
spartacus
18 years ago
OK, try this out - note that you may get security related popups using this if the Outlook Security patches have been applied - I don't know of an easy way to override them, or even if one exists ...
Just as an aside, the moderator(s) may wish to move this to the scripting forum as I haven't seen anything packaging related in this thread (yet) [:)]
Regards,
Spartacus
Const PR_GIVEN_NAME = &H3a06001e
Const PR_INITIALS = &H3a0a001e
Const PR_SURNAME = &H3a11001e
Const PR_7BIT_DISPLAY_NAME = &H39ff001e
Const PR_STREET_ADDRESS = &H3a29001e
Const PR_LOCALITY = &H3a27001e
Const PR_STATE_OR_PROVINCE = &H3a28001e
Const PR_POSTAL_CODE = &H3a2a001e
Const PR_COUNTRY = &H3a26001e
Const PR_TITLE = &H3a17001e
Const PR_COMPANY_NAME = &H3a16001e
Const PR_DEPARTMENT_NAME = &H3a18001e
Const PR_OFFICE_LOCATION = &H3a19001e
Const PR_ASSISTANT = &H3a30001e
Const PR_BUSINESS_TELEPHONE_NUMBER = &H3a08001e
set Application = GetObject("","Outlook.application")
' If there was an error, Outlook probably wasn't Open, so open it now
if err.number <> 0 then
err.clear
set Application = CreateObject("Outlook.application")
if err.number <> 0 then
msgbox "Problem trying to create Outlook object, unable to continue"
wscript.quit
end if
end if
set olemSession = Application.CreateObject("MAPI.Session")
ReturnStatus = olemSession.Logon( Application.GetNameSpace("MAPI").CurrentUser, "", False, False, 0 )
Set myself = olemSession.CurrentUser
msgbox myself.Fields.Item(PR_GIVEN_NAME) & " " & myself.Fields.Item(PR_SURNAME) & " " & myself.Fields.Item(PR_BUSINESS_TELEPHONE_NUMBER)
Just as an aside, the moderator(s) may wish to move this to the scripting forum as I haven't seen anything packaging related in this thread (yet) [:)]
Regards,
Spartacus
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.