Microsoft KB Archive/281509

= How To Use CDO and Visual Basic to Obtain the Exchange Server Version =

Article ID: 281509

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Collaboration Data Objects 1.21
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition

-



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:  In Visual Basic, create a new Standard EXE project. Remove the default Form1. Add a new standard module. Add a reference to Microsoft CDO 1.21 Library.  Paste the following code into the module: Private Declare Sub CopyMemory Lib &quot;kernel32&quot; Alias &quot;RtlMoveMemory&quot; _ (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 &quot;0.0.0.0&quot;. GetReplicaVersion = CStr(tmpVer.Major) & &quot;.&quot; _ & CStr(tmpVer.Minor) & &quot;.&quot; _ & CStr(tmpVer.Build) & &quot;.&quot; _ & 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(&quot;MAPI.Session&quot;) 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 &quot;Version of Exchange Server that services this &quot; _ & &quot;Inbox is: &quot; & GetReplicaVersion(objFolder)

'Clean up. Set objFolder = Nothing objSess.Logoff Set objSess = Nothing End Sub 

Keywords: kbhowto kbmsg KB281509

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.