Howto: Get Free/Busy information using CDO 1.21 and vbs


Below is a sample:


 


'-----------------------------------------------------------
' getfbCDO121.vbs - Get Free/Busy information using CDO1.21 and vbs
' Instructions:
'   Save to a file called getfbCDO121.vbs
'   Do the TODO: sections
'   Run from the command line using:  cscript getfbCDO121.vbs
'------------------------------------------------------------
    Dim ObjSession      'MAPI.Session
    Dim ObjMessage      'MAPI.Message
    Dim ObjAddressEntry 'MAPI.AddressEntry
    Dim sFreeBusy
    Dim sFBFrom
    Dim sFBTo
    Dim sLoginProfileInfo ' This is sLoginServer + lf + sLoginMailbox
    Dim sLoginServer
    Dim sLoginMailbox
    Dim sFBMailbox ' This is the mailbox of the user to get Free/Busy information for.


    ' -----------  Configure ------------------------------
    sLoginServer = "mycompany.com"    ' TODO: Change this to the name of you email server - Example: "NORTHAMERICA" for the Exchange server called "NORTHAMERICA" - you can also use a TCP address.
    sLoginMailbox = "maybemyuser"        ' TODO: Change this to the name of your mail box - Example: "danjones" for danjones@mycompany.com
    sProfileInfo = sLoginServer & vbLf & sLoginMailbox
   
    sFBMailbox = "myuser@mycompany.com"   ' TODO: Change this to the user you want to get Free/Busy Information for. You can also use just the mailbox name, without using the full email address.
                                                       ' Note that the user you log-in with must have access to this mailbox.
    sFreeBusy = ""
    'Specify the date/time of the beginning of the first time slot.
    sFBFrom = "6/4/2003 8:00:00 AM"  ' TODO: Change this
    'Specify the date/time of the end of the last time slot.
    sFBTo = "6/4/2003 6:00:00 PM"    ' TODO: Change this
                            
    ' --------------- Startup a MAPI Session -------------------
    Set ObjSession = CreateObject("MAPI.Session")
    ObjSession.Logon , , False, True, 0, True, sProfileInfo
    Set ObjMessage = ObjSession.Inbox.Messages.Add
    Set ObjRecipColl = ObjMessage.Recipients
    Set ObjOneRecip = ObjRecipColl.Add
           
    'Type the alias of the person or the resource account.
    ObjOneRecip.Name = sFBMailbox
    ObjOneRecip.Resolve
    Set ObjAddressEntry = ObjOneRecip.AddressEntry
                
    'Specify the length of each time slot in minutes.
    'If Interval parameter is less than 1, GetFreeBusy returns
    'CdoE_INVALID_PARAMETER.
           
    Interval = 30
    'Interval parameter determines the number of time slots.
    'For this example, Interval is set to 60 minutes. Therefore,
    'there will be 2 time slots between the StartTime and the EndTime.
    'The first time slot is between 8:00:00-9:00:00 AM.
    'The second time slot is between 9:00:00-10:00:00 AM.
           
    sFreeBusy = ObjAddressEntry.GetFreeBusy(sFBFrom, sFBTo, Interval)
    'Since there are two time slots, the GetFreeBusy method returns a
    'string with length 2. For example, FreeBusy = "21" indicates that
    'there is a tentative commitment during the time slot 1. Also,
    'there is a confirmed commitment during the time slot 2.
   
    WScript.echo "Freebusy: " & sFreeBusy
    ' Each element in the array corresponds to the time-span of
    ' the time interval.
    ' The meaning of each element is as follows:
    '    0 - Available for meetings/appointments during the time slot
    '    1 -At least one tentative commitment during the time slot
    '    2 -At least one confirmed commitment during the time slot
    '    3 -Out-of-office (OOF) for at leastpart of the time slot
           
    ObjSession.Logoff
    Set ObjMessage = Nothing
    Set ObjRecipColl = Nothing
    Set ObjOneRecip = Nothing
    Set ObjAddressEntry = Nothing
    Set ObjSession = Nothing


 

Comments (0)

Skip to main content