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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
David LeeCommented:
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sawmillsamAuthor Commented:
This worked perfectly.  Thanks for your time and knowledge.  
David LeeCommented:
You're welcome.  I'm glad I could help out.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.