Outlook 2007 AutoArchive PST location change VBScript

Good grief, what a complete pain in the neck this was. Outlook stores a lot of its stuff as REG_BINARY values that have a ox00 separating each character. Nasty.

This sub changes the registry value that holds the Outlook AutoArchive location as set via Tools – Options – Other – AutoArchive. I wanted to do this because the default location is in the Local Settings part of the profile – and on roaming profiles this all gets ditched when you log off. So this sub looks for C:\Documents and Settings in the location and sets it to a different place. I know Microsoft don’t like having PST files on network drives, but let’s face it, until fairly recently there wasn’t a lot of choice for most people (intersting how that article has been updated recently in light of Exchange 2010 archiving).

Registry locations obtained from here. They’re different for different versions of Outlook. I’m using Outlook 2007.

You’ll also need the stuff from my other blog post about working with REG_BINARY values in VBScript. And also the regValueExists function.

Sub sortOutlookAutoArchivePST
      Const cKeyRoot = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"
      Const cAutoArchivePSTValue = "001f0324"
      Const cCorrectLocation = "H:\Exchange\Archive.pst"
      Const HKEY_CURRENT_USER = &H80000001
      Const HKEY_LOCAL_MACHINE = &H80000002
      Dim sProfile, sValue, sFilePath, sBinaryFormOfPSTLocation, sKeyPath
      Dim p,i
      Dim aMailProfiles(0)
      Dim oReg

      Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
      oReg.EnumKey HKEY_CURRENT_USER, cKeyRoot, aMailProfiles

      'create reg_binary form of cCorrectLocation in case we need it later
      For i = 1 To Len(cCorrectLocation)
             sBinaryFormOfPSTLocation = sBinaryFormOfPSTLocation & Hex(Asc(Mid(cCorrectLocation,i,1)))&",00,"
      Next
      sBinaryFormOfPSTLocation = sBinaryFormOfPSTLocation & "00,00"

      WScript.Echo "Checking Outlook AutoArchive PST file location"
      For Each sProfile In aMailProfiles
             p=p+1
             sKeyPath = cKeyRoot & "\" & sProfile & "a0d020000000000c000000000000046"
             sValue = "HKCU\" & sKeyPath & "\" & cAutoArchivePSTValue
             If regValueExists(sValue) Then
                   sFilePath = regReadBinary(sValue)
                   WScript.Echo "Mail profile " & sProfile & " has " & sFilePath
                   If InStr(1,sFilePath,"c:\documents and settings",vbTextCompare) Then                        
                         WScript.Echo "Setting AutoArchive location to " & cCorrectLocation
                         regWriteBinary "HKEY_CURRENT_USER\" & sKeyPath, cAutoArchivePSTValue, sBinaryFormOfPSTLocation
                   Else
                         WScript.Echo "Outlook AutoArchive location probably ok"
                   End If
             Else
                   WScript.Echo "No Outlook AutoArchive settings found in profile " & sProfile & ", adding default location"
                   WScript.Echo sKeyPath
                   regWriteBinary "HKEY_CURRENT_USER\" & sKeyPath, cAutoArchivePSTValue, sBinaryFormOfPSTLocation
             End If
      Next
      If p=0 Then
             WScript.Echo "No Mail Profiles found for this user"
      End If
End Sub
This entry was posted in Outlook, Scripting, Windows and tagged , , , , , , , . Bookmark the permalink.

2 Responses to Outlook 2007 AutoArchive PST location change VBScript

  1. Eric says:

    Has anyone actually tried this? I am trying to setup this for my network to move files from local to M network drive.

  2. rcmtech says:

    Hi Eric, it does work, I’ve been using it for months. However, it will not move existing autoarchive PST files, it just changes the default location for new ones.
    As an aside, I think the registry location may be different for Outlook 2010, but I’ve not been able to verify this yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s