Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How to Determine the Size of an Exchange 2000 Server Mailbox with ADO


View products that this article applies to.

This article was previously published under Q255992

↑ Back to the top


Summary

You can use ActiveX Data Objects (ADO) to determine the size of a user's mailbox. This artlcle contains sample code that demonstrates how to do this.

↑ Back to the top


More information

The following function determines the size of a mailbox by using ADO:

Private Sub Form_Load()
    Dim strMailBoxName As String
    strMailBoxName = "MyAlias"
    Debug.Print "Mailbox Size: " & dblGetMailboxSize(strMailBoxName)
End Sub

Private Function dblGetMailboxSize(strMailBoxName As String) As Double
    'Requires reference to:
    'Active DS Type Library (activeds.tlb)
    'Microsoft ActiveX Data Objects 2.5 Library  (msado15.dll)
    
    Dim Info As New ADSystemInfo
    Dim sDomainName As String
    Dim sUserName As String
    Dim mailboxSZ As Double
    Dim sURL As String
 
    Dim sSQL As String
    Dim Rs As New ADODB.Recordset
    Dim Rec As New ADODB.Record
    
    mailboxSZ = 0
    sDomainName = Info.DomainDNSName
    sUserName = strMailBoxName
    
    sURL = "file://./backofficestorage/" & sDomainName & _
            "/MBX/" & sUserName
    Rec.Open sURL
    
    sSQL = "Select"
    sSQL = sSQL & " ""http://schemas.microsoft.com" & _
                  "/exchange/foldersize"" "
    sSQL = sSQL & ", ""DAV:displayname"" "
    sSQL = sSQL & " from scope ('shallow traversal of " & Chr(34)
    sSQL = sSQL & sURL & Chr(34) & "')"
    sSQL = sSQL & "Where ""DAV:isfolder""=true"
    
    Rs.Open sSQL, Rec.ActiveConnection
    
    If Not Rs.EOF Then
        Rs.MoveFirst
    End If
    
    While Not Rs.EOF
        'Uncomment the following lines if you would like to<BR/>
        'see the size of each folder
        'Debug.Print Rs.Fields("DAV:displayname").Value
        'Debug.Print Rs.Fields("http://schemas.microsoft.com" & _
        '                     "/exchange/foldersize").Value
        mailboxSZ = mailboxSZ + _
                    Rs.Fields("http://schemas.microsoft.com" & _
                    "/exchange/foldersize").Value
        Rs.MoveNext
    Wend
    dblGetMailboxSize = mailboxSZ
    Rs.Close
    Rec.Close
End Function
				

↑ Back to the top


Keywords: KB255992, kbprogramming, kbhowto

↑ Back to the top

Article Info
Article ID : 255992
Revision : 5
Created on : 2/22/2007
Published on : 2/22/2007
Exists online : False
Views : 307