How To Use CDO and Visual Basic to Obtain the Exchange Server Version (281509)



The information in this article applies to:

  • Collaboration Data Objects (CDO) 1.21
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Visual Basic Learning Edition for Windows 6.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0

This article was previously published under Q281509

SUMMARY

This article demonstrates how to access the version of Exchange Server by using Collaboration Data Objects (CDO) in Microsoft Visual Basic.

MORE INFORMATION

The version of Exchange Server is stored in the PR_REPLICA_VERSION property on the Inbox. However, the PR_REPLICA_VERSION property is an 8-byte signed integer (PT_I8), which Visual Basic does not support. Therefore, CDO returns the PT_I8 value as Double.

To retrieve the actual version fields, you need to create your own Type structure to hold the values and then copy the memory contents of the Double variable into the structure.

To do this, follow these steps:
  1. In Visual Basic, create a new Standard EXE project.
  2. Remove the default Form1.
  3. Add a new standard module.
  4. Add a reference to Microsoft CDO 1.21 Library.
  5. Paste the following code into the module:
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
        (Destination As Any, Source As Any, ByVal nLength As Long)
    
    Private Type EXCH_VER
        Revision As Integer
        Build As Integer
        Minor As Integer
        Major As Integer
    End Type
    
    Public Function GetReplicaVersion(objFolder As MAPI.Folder) As String
        Dim dblValue As Double, tmpVer As EXCH_VER
    
        'Because CDO does not define this constant, we need to.
        Const CdoPR_REPLICA_VERSION = &H664B0014
    
        On Error Resume Next
    
        'Get the server version for the folder.
        dblValue = objFolder.Fields(CdoPR_REPLICA_VERSION)
    
        'Only copy the memory contents to our structure when the 
        'previous call succeeds.
        If Err = 0 Then
            CopyMemory tmpVer, dblValue, LenB(tmpVer)
        End If
    
        'Now set the return value. If we couldn't read the property,
        'this function returns "0.0.0.0".
        GetReplicaVersion = CStr(tmpVer.Major) & "." _
            & CStr(tmpVer.Minor) & "." _
            & CStr(tmpVer.Build) & "." _
            & CStr(tmpVer.Revision)
    End Function
    
    Public Sub Main()
        Dim objSess As MAPI.Session, objFolder As MAPI.Folder
    
        'Create the CDO Session object and logon.
        Set objSess = CreateObject("MAPI.Session")
        objSess.Logon , , True, True
    
        'Get the current user's Inbox.
        Set objFolder = objSess.GetDefaultFolder(CdoDefaultFolderInbox)
    
        'Now display the Exchange Server version for the Inbox.
        MsgBox "Version of Exchange Server that services this " _
            & "Inbox is: " & GetReplicaVersion(objFolder)
    
        'Clean up.
        Set objFolder = Nothing
        objSess.Logoff
        Set objSess = Nothing
    End Sub
    					

Modification Type:MinorLast Reviewed:7/13/2004
Keywords:kbhowto kbMsg KB281509