Code to open PST in an Outlook 2003 profile

We are migrating users from locally stored pst files to Exchange profiles using a deployed PRF.

We are not going to import the data in the PST files for the users rather we will ask them to open the PST in the newly created exchange file and copy/paste any data they wish to keep from the old PST into the new OST mailbox.  (Opening the file would normally be accomplished using File->Open->Outlook data file... on the file menu).

Assuming all users' PSTs are stored in a default directory, is there any code (vbs or batch file) that can automate "opening" the pst for the user such that before the user first logs into Outlook under the new Exchange profile, the user's old PST is already opened\added as an additional "Personal Folders" directory?


Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

David LeeConnect With a Mentor Commented:
The following code snippet (VBScript) will do the job.  Copy the code and paste it into Notepad.  Save the file with a .vbs extension.  You can then run it from a batch file using the CSCRIPT or WSCRIPT script processors.
Dim olkApp, olkNS, olkTempFolder, objFSO, objFolder, objFile
Set olkApp = CreateObject("Outlook.Application")
Set olkNS = olkApp.GetNamespace("MAPI")
'Change the profile name on the following line as needed
olkNS.Logon "Outlook"
Set objFSO = CreateObject("Scripting.Filesystemobject")
'Change the folder path on the following line as needed
Set objFolder = objFSO.GetFolder("C:\")
For Each objFile In objFolder.Files
    olkNS.AddStore objFile.Path
    Set olkTempFolder = olkNS.Folders.GetLast
    olkTempFolder.Name = objFile.Name
Set objFile = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
Set olkNS = Nothing
Set olkApp = Nothing

Open in new window

David LeeCommented:
Hi, sawmillsam.

It is possible to add a PST file to an Outlook profile via scripting.  But, that can't be done without opening Outlook.  The user would need to be logged in to do this.  If that's not a show stopper, then I'll be glad to post the code for doing this.
sawmillsamAuthor Commented:
Thanks for the comment, BlueDevilFan.  I would be interested in seeing that code - so is it just VBA code then?  Is it not something that could be added to/called from a batch file that also executes a PRF on the local client's machine?  That is, the batch (executed by a logged in user) waits for the PRF execution to finish (Outlook remains open upon its completion) and then this next bit of code to add the PST runs.  Thanks, again.
sawmillsamAuthor Commented:
This worked perfectly.  Thanks for your time and knowledge.  
David LeeCommented:
You're welcome.  I'm glad I could help out.
All Courses

From novice to tech pro — start learning today.