1
votes

I have MS Exchange account as my primary mail account in my default mail profile. I need to get its mail address programmatically in some VBScript.

I've got Outlook installed, so I can do it like this:

MsgBox CreateObject("Outlook.Application").GetNamespace("MAPI").CurrentUser.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E")

But only when Outlook is running, also I've got security prompts in Outlook, so I can't use this approach.

I've found that a bunch of information about profiles and accounts is stored in registry under HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Outlook\Profiles\ I've found Email value for POP3 and IMAP accounts in subkeys of 9375CFF0413111d3B88A00104B2A6676 in default profile, but none of that for Exchange account.

Where can find a value for Exchange account mail address of current user in registry?

2

2 Answers

2
votes

enter link description hereThe name of your default profile is stored in

HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\DefaultProfile

Use Redemption (RDO) in stead of the standard Microsoft tools (CDO), you'l have better tools and no security prompts.

RDOSession.Logon method, which takes several parameters, including the MAPI profile name (pass an empty string to use the default MAPI profile)

set Session = CreateObject("Redemption.RDOSession")
Session.Logon
set Inbox = Session.GetDefaultFolder(olFolderInbox)
for each Msg in Inbox.Items
  Debug.Print(Msg.Subject)
next

Another option is to use ADSI and do an LDAP query. See this answer. Also see this.

Set MyUser = GetObject ("LDAP://CN=Administrator,CN=Users,DC=sunnydale,DC=muni")
For each email in MyUser.proxyAddresses
       WScript.Echo email
Next
1
votes

I didn't like the idea of using Redemption for that case. Its not free and requires additional movements to use. Anyway, I found an answer to my original question.

To get user primary SMTP address of the Outlook Exchage account on the end-user computer you need to search registry down the key of default mail profile (HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Outlook\Profiles\<default profile name> or HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\<default profile name> for older versions of Outlook) for the value named 001f6641. This value data has binary format and contains mail address in the form like this SMPT:[email protected], just cut the SMTP: part out an you get mail address.

The bad part that you can't make it with Outlook 2003. For that case you can search registry the same way for the value named 001e660b that contains legacyExchangeDN. Then you make an LDAP query (probably to Exchange AD by default) to find person with that legacyExchangeDN. What you need is proxyAddresses field. It has multiple values and that one that starts with SMTP: (uppercase is important), contains primary SMTP address.