PRB: CurrentUser of CDO Session Object Returns Wrong User NameID: Q223446
|
The CurrentUser property of the Collaboration Data Objects (CDO) Session object might return the Internet Mail account name instead of the Exchange user name. This problem occurs when your program logs on to a mail profile that has both Microsoft Exchange Server service and Internet E-Mail service.
Exchange store does not act as the provider for the primary identity until the store has been opened.
You need to have a reference to the Exchange store to get Exchange to be the provider for the primary identity.
For example, having a reference to the RootFolder of the private message store, before reading the value of the CurrentUser property solves the problem:
Set objSession = CreateObject("MAPI.Session")
objSession.Logon , , True
For Each objInfoStore In objSession.InfoStores
'Check CdoPR_PROVIDER_DISPLAY (&H3006001E)
On Error Resume Next
If InStr(objInfoStore.Fields(&H3006001E), "Microsoft Exchange") Then
Set objFolder = objInfoStore.RootFolder
Exit For
End If
Next
MsgBox "The Current User is " & objSession.Currentuser
This behavior is by design.
To reproduce the problem, please follow these steps:
Private Sub Form_Load()
Dim objSession As New MAPI.Session
'Log on to the existing Outlook Session
Set objSession = CreateObject("MAPI.Session")
objSession.Logon "CDOTest"
MsgBox " The Current User is " & objSession.CurrentUser
objSession.LogOff
Set objSession = Nothing
End Sub
For more information about being a provider for the primary identity, please see the following topic on Microsoft Developer Network (MSDN):
IMAPISession::QueryIdentity
Additional query words: kbCDO kbGrpMsg kbCDO100a kbCDO110 kbCDO120 kbCDO121 kbMsg kbVB
Keywords : kbCDO kbCDO100a kbCDO110 kbCDO120 kbCDO121 kbMsg kbGrpMsg
Version : WINDOWS:1.0a,1.1,1.2,1.21
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: April 29, 1999