PDA

View Full Version : Programmatic set up of direct booking


kl34i2
12-15-2005, 09:21 AM
We use exchange mailboxes set up with direct booking (auto accept/decline meetings) to represent our rooms and conference lines. I've managed to automate the creation of the AD account and mailbox enabling of these accounts, but can't seem to get the direct booking to work properly. The process I follow is:
1. Create AD Accounts
2. Mailbox Enable account
3. Wait X minutes until Exchange stamps it with an e-mail address
4. Using CDO, log in to the mailbox and create meetings in the future (to prevent abuse of resources)
5. Set FreeBusyMonths to 9
6. Delete PR_FREEBUSY_DATA and add PR_RECALCULATE_FREEBUSY to the "LocalFreeBusy" message of the mailbox
7. Get "NON_IPM_SUBTREE", then "SCHEDULE+ FREE BUSY" and find Free/Busy message of the current resource.
8. Set PR_SCHDINFO_AUTO_ACCEPT_APPTS=1, PR_SCHDINFO_DISALLOW_OVERLAPPING_APPTS=1, PR_SCHDINFO_DISALLOW_RECURRING_APPTS=0
9. Save message
10. Logoff

I then wait a while and try to schedule a meeting with the resource, but I get an error message stating "unable to directly book resource, an object is missing". So I then create a profile for the resource and log on to it with Outlook. The FreeBusy months is set to 2 instead of the 9 I set it to. When I check the direct booking checkboxes, none of them are checked.

Does anyone have any solutions to this? Thanks in advance!!

CowboyOtaku
12-30-2005, 07:11 PM
I've been working on the same thing for my company for a little while now (far too long, really), and your post gave me the a clue about the final piece I was missing. My own programmatic setup of our auto-booking resource mailboxes appears to be working now! To answer your questions:

Firstly, if you set the Free/Busy publishing period in CDO via something like Session.SetOption("FreeBusyMonths", 9), it should work (from what I hear), but it will not show up in Outlook. The only way (I know of) to set it so that it also appears in Outlook is to set it via the Outlook interface. While it's not terribly difficult to set up a SendKeys script to do this (I know of no way to use the Outlook Object Model and its commandbars to work with the popup dialogs they open), that would be awfully unreliable, I suspect (this comes from personal experience). We just settle for having the functionality without having it show up in Outlook, since nobody is really opening our auto-booking resource mailboxes anyway.

More importantly, the settings changes you're making in step 8 may also need to be made on the LocalFreebusy message. Coincidentally, before I read your post, I was making these changes on the LocalFreebusy, and not on the public one. They would show up in Outlook fine, but the mailbox would not auto-accept incoming messages (until I pressed "OK" to that panel in Outlook, which sets the properties in the public free busy message as well). Once I set them on the public free busy message as you do, it started working 100% (again, only as far as I can tell). So here's how I do it...keep in mind, even I consider my method to be pretty darn messy, but I know of no other way to do it right now. Please forgive me in advance, I suppose it's possible that you're using Extended MAPI, but for now, I'll assume you're using (or familiar with) CDO, since that's what I'm using.

1. Get the LocalFreebusy message. Note: In Outlook 2003 cached profiles, the "FreeBusy Data" folder does not exist. Fortunately, we don't have to worry about that with a CDO session. In VERY abbreviated code:
oSessionRoot = oSession.GetFolder("")
oFolders = oSessionRoot.Folders
oFolder = oFolders.Item("FreeBusy Data")
oMessages = oFolder.Messages
Return oMessages.Item("LocalFreebusy")

There are "cleaner" ways to get to this message (ways involving Entry ID's, rather less easy to type), but you get the idea. Once you have the message, just use its Fields to set those properties as you need to.

2. If the LocalFreebusy message doesn't exist (as it won't on new mailboxes that haven't been opened in Outlook), you need to create it. While I'm sure it's possible to create it directly from code, I don't want to go there. From what I've read, as an Outlook-created message, it's best to muck with it as little as possible. Creating it from scratch is probably something that should only be attempted by a Dmitry Streblechenko type of guru, or an MS Outlook programmer. Thus, the only way I'm currently comfortable in creating it is by having Outlook do it for me (the really messy part of my app, which I hate. Alternative suggestions would be SO helpful!).

I wrote a little routine that generates a .PRF file for a mailbox, then runs Outlook using the /cleanfreebusy switch with the /importprf switch to automatically log into the mailbox and generate the LocalFreebusy message. I also use a short Outlook VBA macro stored in an external, signed .OTM file to have Outlook automatically close itself when it's done (using the /altvba and /autorun switches). In this way, I can run Outlook synchronously from a VB.NET application in a fairly reliable manner, and have it generate the LocalFreebusy message for new mailboxes. It might be possible to use the Outlook Object Model to generate the LocalFreebusy file by using the commandbars to run the Tools | Send/Receive | Free/Busy Information command, but I haven't figured out just what circumstances are required for that command to actually be enabled. Again, it is also possible to use a SendKeys routine to have Outlook do it (going to Tools | Options | Calendar Resources... | Free/Busy Options... and pressing OK is sufficient, plus you could use this to set your Free/Busy publishing months too), but I can't recommend it as a reliable approach (from personal experience).

Once the LocalFreebusy message is generated, just get it (perhaps using a way similar to what I described above) and set these resource properties on it too, identically to how you're setting them for the user's Free busy message stored in their site's SCHEDULE+ FREE BUSY system folder.

3. You should also consider setting the Default ACE on the Calendar to "Author" and on the FreeBusy Data folder to "Editor", as Outlook does when you select "Set standard resource permissions for all users". That's a whole different exercise that uses the ACL.dll (if you're using CDO like me). It's not too tough, but it's a lot more code than I can write here.

4. I also noticed that Outlook 2003 sets a few other properties on the two Freebusy messages when it is used to set up resource scheduling options. Specifically, it creates &H68410003, 0x6842000B, &H6843000B, and &H686A0102, and a named one (urn:schemas-microsoft-com:office:outlook#fixupfbfolder, guid: {00020329-0000-0000-C000-000000000046}). I'm not sure what these properties are for, but they appear to be related to Freebusy data, and don't appear to be necessary for automated resource booking to work. On new mailboxes, they seem to always have the same values, and the value for &H686A0102 seems to always start as the binary value represented by the hex string "CDAFDEBE14000000030000000000000014000000". This appears to be a prefix for additional Freebusy data (perhaps patterns or the map), and this prefix gets changed slightly depending on how long it is. I played around with it a bit, but did not really attempt to decipher or use it, so I'm leaving it alone. I suspect I could shed more light on it be correlating it with the information in the Outlook 2003 Free/Busy API, but that's beyond my needs right now. If you or anyone has more info about these properties, it would be welcome knowledge.

5. I also attempted to allow my app to set up Delegates for resource mailboxes. I got pretty close to having it working (I think), but I ran out of time. I created a tweaked version of the Rule.dll (from the C++ source code distributed with the Exchange 5.5 SDK) to allow me to create or modify the hidden Inbox delegate rule. You can use CDO to work with many of the delegate related properties that show up on the LocalFreebusy message, but these don't really seem to do anything that I can tell (maybe they are also set on the public free busy message, I didn't get a chance to check). Rather, Outlook seems to use the "public-delegates" Active Directory attribute directly to list the mailbox's delegates. With the modified Rule.dll, the ability to modify the various folder ACL's as necessary, and the ability to modify the "public-delegates" AD attribute, I suspect one could programmatically add or remove delegates to a mailbox (despite Microsoft's insistance that it isn't supported or even possible), but I'm not sure. Again, anyone with knowledge or experience with this, please share!

One last bit of advice for other CDO programmers, if you aren't already using the Exchange 2003 Server version of the CDO.DLL, try it out. It skips all those important-to-have-in-a-client-but-incredibly-annoying-in-a-program security popups that come with the Outlook version. And if you want code samples or have other questions related to this thread, post them here. I'm subscribed to this thread, and I'll respond as I can.

PS - Just for Googlers' sake (since that's how I found this), the properties you're talking about are more commonly known as the following constants:

PR_PROCESS_MEETING_REQUESTS = &H686D000B
PR_DECLINE_RECURRING_MEETING_REQUESTS = &H686E000B
PR_DECLINE_CONFLICTING_MEETING_REQUESTS = &H686F000B

The delegate properties on the LocalFreebusy message are as follows:

PR_DELEGATES_DISPLAY_NAMES = &H6844101E
PR_DELEGATES_DISPLAY_NAMES_W = &H6844101F
PR_DELEGATES_ENTRYIDS = &H68451102

kl34i2
02-04-2006, 04:12 PM
Wow! Now this is great news to see someone else trying to accomplish the same! Thank you for the excellent post and to simply put it, I had quite given up on this. I'm still trying to work through making it fully automated without having to use Outlook since the server which hosts the application is not allowed to have Outlook installed on it. I just read this post, but wanted to thank you for taking the time to respond!

I'm gonna play around with your suggestions and your ideas and see if there isn't somewhere that can be modified. Fortunately, I may be able to take this new information to Microsoft and not get the same "this is a consultation call" I got last time.

MeJean
02-13-2007, 04:09 PM
CowboyOtaku
Do you mind sharing your program? We are in trouble with our DST hotfix and resource mailboxes, we want to switch off all automatic declines for a while and I assume we can do that with your code.

Thanks,
MeJean