Share via


List delegates of the Outlook Mailbox using CDO 1.2.1 via VBScript

I have recently worked out a VBScript to list delegate of the Outlook Mailbox using CDO 1.2.1 via VBScript and thought of share it with you all, here is the sample code:

NOTE: Following programming examples is for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This sample code assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. This sample code is provided for the purpose of illustration only and is not intended to be used in a production environment.

  
 Dim objSession 
 Dim strProfileInfo 
 Dim strServer 
 Dim strMailbox 
 Dim objFolder
 Dim objMessages
 Dim objMessage
 Dim oFields
 Dim oField1
 Dim oField2
 Dim oFBFolder
  
 'TODO:Change Server and Mailbox info
 strServer="Server"
 strMailbox="User"
  
 strProfileInfo = strServer & vbLf & strMailbox
  
 Set objSession = CreateObject("MAPI.Session")
 objSession.Logon , , False, False, , True, strProfileInfo
  
 writelog( "Mailbox")
         
     writelog( "  ==> ")
     writelog( objSession.CurrentUser)
     writelog( vbCrLf)
 Msgbox "Logged On!!!"
  
 ' Reference the root folder by passing ID of ""
 Set oRoot = objSession.GetFolder("")
  
 'Connect to the Freebusy folder
 Set oFBFolder = oRoot.Folders.Item("Freebusy Data")
     Set objMessages = oFBFolder.Messages
  
     For Each objMessage In objMessages
  
         If objMessage.subject = "LocalFreebusy" Then
             'Get the message fields
  
             Set oFields = objMessage.Fields
             
             On Error Resume Next
  
     For i = 0 to UBound(oFields.Item(&H6844101E).Value(0))
   
                 Set oField1 = oFields.Item(&H6844101E)  ' PR_SCHDINFO_DELEGATE_NAMES
                        writelog "DELEGATE NAMES  ==> " & oField1.Value(0)(i)
                     writelog( vbCrLf)
  
                           Set oField2 = oFields.Item(&H686B1003) ' PR_DELEGATE_FLAGS
               writelog "Delegate can see private  ==> " & oField2.Value(0)(i)
                           writelog( vbCrLf)
        Next
     End iF
 Next
  
 objSession.Logoff
  
 Set objSession =Nothing
  
 Set oField1 = Nothing
 Set oField2 = Nothing
 Set oFBFolder = Nothing
 Set oRoot = Nothing
  
 Msgbox "Done!!!"
  
 Sub WriteLog(ByVal strMessage)
     Dim fs
     Set fs = CreateObject("Scripting.FileSystemObject")
     Dim file
     Dim sScriptPath
     sScriptPath = Left(WScript.ScriptFullName, InstrRev(WScript.ScriptFullName, "\"))
     Set file = fs.opentextfile(sScriptPath & "DelegateListLog.txt", 8, True)
     file.Write strMessage
     file.Close
 End Sub

Please refer to the following MAPI properties used in the above sample to list delegates of the mailbox:

-
PidTagScheduleInfoDelegateNames Canonical Property
https://msdn.microsoft.com/en-us/library/cc839497.aspx

Contains the names of the delegates.  
  
  
Associated properties: PR\_SCHDINFO\_DELEGATE\_NAMES, PR\_SCHDINFO\_DELEGATE\_NAMES\_A, PR\_SCHDINFO\_DELEGATE\_NAMES\_W  
  
  
Identifier: 0x6844

If you interested in exploring further details regarding how delegate settings works in Outlook then refer to:

-
[MS-OXODLGT]: Delegate Access Configuration Protocol Specification
https://msdn.microsoft.com/en-us/library/cc425488.aspx

However, if you just targeting Exchange Server 2007, I would highly recommend you to use EWS(Exchange Web Services)

Delegate Access and Delegate Access Management with Exchange Web Services

Comments