Tuesday, July 10, 2007

Setting the Homepage on a Outlook Folder via a script

I’ve had a number of people ask this question in the past so I thought I’d post up a script to help out those they may want to look at doing this.

When you set the Outlook homepage within Outlook it configures the PR_FOLDER_WEBVIEWINFO or http://schemas.microsoft.com/mapi/proptag/0x36DF0102 property. This property is a Binary property who’s format is undocumented but using a Mapi editor like OutlookSpy or MfcMapi you can work out the format that this follows. The basic format is

dwVersion: 0x00000002
dwType: 0x00000001
dwFlags: 0x00000001
dwUnused: 0x0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
cbData: 0x188 (000000BC)
bData: http://yoururl.com

If you want to set this property in a script the 3 values you need to worry about are

dwFlags If this is set to 1 then the check box in Outlook for “Show homepage by default for this folder” will be checked.

cbData is the number of bytes (8 bits or 2 hex digits) or the url in Bdata + the spacers

bData is the URL of the webpage you want to point to encoded in Hex.

The following script handles encoding URL’s that are up to 255 characters long if you want to have URL’s that are longer than 255 charterers then you need to change the code for cbData. The rest of the code builds the binary property. The AsciiToHex to function encodes the Ascii string 1 byte for each letter hence the extra padding needed.

The one thing to note is this is a unsupported thing to do so make sure you do plenty of your own testing first.

I’ve created 2 versions of the script one version uses codex and the other cdo1.2 they do basically the same thing. They first check for an instance of a folder in a mailbox (the cdo1.2 version only checks the Root folder). If an instance of that folder is found then its sets the homepage property on the folder else it creates the folder and sets the homepage. In this sample the folder is called webfolder and it sets the homepage of that folder to a search about coffee tasting in Sydney.

I’ve put a downloadable copy of the script here the code itself looks like.

homepage = "http://yoururl.com"
dwVersion = "02"
dwType = "00000001"
dwFlags = "00000001"
dwUnused = "00000000000000000000000000000000000000000000000000000000"
bData = AsciiToHex(homepage)
cbDataSize = cstr(ubound(bData)+1)
propval = dwVersion & dwType & dwFlags & dwUnused & "000000" & Hex(cbDataSize) & "000000" & Join(bData,"")

set rec = createobject("ADODB.Record")
rec.open "file://./backofficestorage/domain.com/MBX/mailbox/webfolder/", ,3,33562624
rec.fields("http://schemas.microsoft.com/mapi/proptag/0x36DF0102").value = propval
rec.fields.update
rec.close


Function AsciiToHex(sData)
Dim i, aTmp()
ReDim aTmp((Len(sData)*2) + 1)
arnum = 0
For i = 1 To Len(sData)
aTmp(arnum) = Hex(Asc(Mid(sData, i)))
arnum = arnum + 1
aTmp(arnum) = "00"
arnum = arnum + 1
Next
aTmp(arnum) = "00"
arnum = arnum + 1
aTmp(arnum) = "00"
ASCIItoHex = aTmp
End Function