PRB: CurrentUser of CDO Session Object Returns Wrong User Name

ID: Q223446


The information in this article applies to:


SYMPTOMS

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.


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:

  1. Create a profile named "CDOTest" including both Microsoft Exchange Service and Internet Mail Service information services.


  2. Create a new Microsoft Visual Basic application.


  3. Have a reference to Microsoft CDO 1.2 library from the Microsoft Visual Basic application.


  4. 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.


REFERENCES

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