Microsoft KB Archive/223446

= PRB: CDO (1.x) Session.CurrentUser Returns Wrong User Name =

Article ID: 223446

Article Last Modified on 3/4/2004

-

APPLIES TO


 * Microsoft Collaboration Data Objects 1.0a
 * Microsoft Collaboration Data Objects 1.1
 * Microsoft Collaboration Data Objects 1.2
 * Microsoft Collaboration Data Objects 1.21

-



This article was previously published under Q223446



SYMPTOMS
The CurrentUser property of the Collaboration Data Objects (1.x) 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.



CAUSE
Exchange store does not act as the provider for the primary identity until the store has been opened.



RESOLUTION
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



STATUS
This behavior is by design.



MORE INFORMATION
To reproduce the problem, please follow these steps:  Create a profile named "CDOTest" including both Microsoft Exchange Service and Internet Mail Service information services. Create a new Microsoft Visual Basic application. Have a reference to Microsoft CDO (1.x) library from the Microsoft Visual Basic application.  Paste following code into the application and run it: 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 

The CurrentUser property returns the Internet Mail account name.

<div class="references_section">