'Registry key to find pst locations?

For outlook 2010 we had the outlook profiles set under:- HKCU\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows Messaging Subsystem\\Profiles.

Similar location for outlook 2013 is:- HKCU\\Software\\Microsoft\\Office\\15.0\\Outlook\\Profiles.

In my program, I first look for 2013 profiles, getting an exception I look for 2010 profile location.

But this would fail if outlook is downgraded to 2010. As the registry key for outlook 2013 would still be at same place.

Any suggestions on this. Probably, if I can first get the correct version of outlook installed and then search the right key rather than using the try....except....block?

Majorly I want to list all the pst files attached to Outlook.



Solution 1:[1]

There is a record of attached PSTs in the registry but it appears that it is more a record of PST files that are indexed by Outlook's search, so I'm not sure if clearing out the indexing cache would remove the entries from the registry or not at one point but here are two locations that I have used:

Office 2007

HKCU:\software\Microsoft\Office\12.0\Outlook\Catalog

Office 2013

HKCU:\software\Microsoft\Office\15.0\Outlook\Catalog

Also note that this seems to be a history of attached archives instead of a list of actively attached archives. To get at the actively attached archives the only method I had found was using the COM object (Outlook.Application) but this isn't very nice because initializing the COM object of course starts Outlook so if you are pulling information in the background it might upset end users.

That being said here is a little PowerShell script that will both dump the attached archives and search the registry for a history of attached archives and place the results on the desktop.

'****************************Currently attached archives' | Out-File 

$Env:UserProfile\Desktop\ArchiveHistory.txt -append

#NOTE: This launches Outlook if it is not already running.
$Outlook = New-Object -Comobject Outlook.Application
$Namespace = $Outlook.GetNamespace('MAPI')
$Mailboxes = $Namespace.Stores | where {$_.ExchangeStoreType -eq 1} | Select-Object DisplayName
$AttachedArchives = $Namespace.Stores | where {$_.ExchangeStoreType -eq 3} | Select-Object DisplayName,FilePath
$MailBoxes | Out-File -FilePath $Env:UserProfile\Desktop\OutlookMailboxes.txt
$AttachedArchives | Out-File -FilePath $Env:UserProfile\Desktop\OutlookAttachedArchives.txt

'****************************Archive History for Office 2007' | Out-File $Env:UserProfile\Desktop\ArchiveHistory.txt -append

get-item HKCU:\software\Microsoft\Office\12.0\Outlook\Catalog | select -expandProperty property | where {$_ -match '.pst$'} | Out-File $Env:UserProfile\Desktop\ArchiveHistory.txt

'****************************Archive History for Office 2010' | Out-File $Env:UserProfile\Desktop\ArchiveHistory.txt -append

get-item HKCU:\software\Microsoft\Office\14.0\Outlook\Catalog | select -expandProperty property | where {$_ -match '.pst$'} | Out-File $Env:UserProfile\Desktop\ArchiveHistory.txt

'****************************Archive History for Office 2013' | Out-File $Env:UserProfile\Desktop\ArchiveHistory.txt -append

get-item HKCU:\software\Microsoft\Office\15.0\Outlook\Search\Catalog | select -expandProperty property | where {$_ -match '.pst$'} | Out-File $Env:UserProfile\Desktop\ArchiveHistory.txt -append

'****************************Archive History for Office 2016' | Out-File $Env:UserProfile\Desktop\ArchiveHistory.txt -append

get-item HKCU:\software\Microsoft\Office\16.0\Outlook\Search\Catalog | select -expandProperty property | where {$_ -match '.pst$'} | Out-File $Env:UserProfile\Desktop\ArchiveHistory.txt -append

Solution 2:[2]

The PST file locations are stored in the profile sections in the registry. The officially supported API designed to access and manipulate the profile data is the IProfAdmin interface (you can play with it in OutlookSpy (I am its author) if you click the IProfAdmin button). PST path is stored in the PR_PST_PATH property. Extended MAPI can only be accessed from C++ or Delphi.

If Extended MAPI in C++ or Delphi is not an option, you can use ProfMan (it comes with the distributable version of Redemption - I am also its author); ProfMan can be used from any language. The following script (VB) retrieves PST files names from all local profiles:

'Print the path to all the PST files in all profiles
 PR_PST_PATH = &H6700001E

 set Profiles=CreateObject("ProfMan.Profiles")
 for i = 1 to Profiles.Count
   set Profile = Profiles.Item(i)
   set Services = Profile.Services
   Debug.Print "------ Profile: " & Profile.Name & " ------"
   for j = 1 to Services.Count
     set Service = Services.Item(j)
     If (Service.ServiceName = "MSPST MS") or (Service.ServiceName = "MSUPST MS") Then
      MsgBox Service.Providers.Item(1).ProfSect.Item(PR_PST_PATH)
     End If
   next
 next

You can also retrieve PST file names from PST stores using the Outlook Object Model (but that requires Outlook to be running, and you can only do that for the currently used profile) - use the Store.FilePath property:

set vApp = CreateObject("Outlook.Application")
for each vStore in vApp.Session.Stores
  MsgBox vStore.DisplayName & " - " & vStore.FilePath
next

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Dmitry Streblechenko