«•»


Automating Outlook’s Inbox Repair Tool (ScanPST)

Date September 2, 2008 : Permalink :

File-Schedule

Update: This has been tested in Outlook 2010, 2007 & 2003

I find that Outlook’s Personal Folder (.pst) files have a haphazard way of getting corrupted – which obviously impacts daily performance as well as reliability of my email achieve. Microsoft’s Inbox Repair Tool (ScanPST) diagnoses and repairs corrupt .pst/.ost files to make sure the file structure is intact, but the process requires more manual intervention than I care for. So, here’s how I made Outlook’s Inbox Repair process completely automated:

Step 1: Download some 3rd party utilities!

  1. Download NirCmd.zip.
    In order to run the ScanPST utility against your .pst/.ost files, Outlook must be shutdown. While there isn’t a way to do what we need natively in Windows, NirCmd (free) allows us to accomplish the task gracefully – meaning Outlook will not shut down when unsaved content exists (in which case the Repair will be skipped for this instance).
    (Note: If you prefer to forcefully end Outlook, you can do so using process.exe 1 . Of course, doing this could cause corruption – which is what we’re trying to avoid/fix!)
  2. Extract nircmdc.exe2 to ‘C:\\Windows\System32′.
    (Note: I don’t usually like to install 3rd party executables to WindowsSystem32. In this case, however, I feel these simple cli utilities don’t justify additions to my Path entry. If you wish to install somewhere else, you can add the location to your Path3 or add the full path into the script file.)
  3. Download cmdscan.zip.
    Quester’s cmdscan (free) allows us to run ScanPST without any user interaction.
  4. Extract cmdscan.exe to ‘C:\\Windows\System32′
  5. Download autopst.bat – my batch file template.

The next Steps will outline what is happening in the batch file:

Step 2: Make sure Outlook is not running/Close Outlook if it is.

  1. (informational) To gracefully close outlook, the script executes:
    nircmdc closeprocess outlook.exe.

    To test your nircmd install,
    open Outlook and execute this command from the command prompt.
  2. (informational) We want to wait for Outlook to close because the Repair Tool will not analyze/fix an open .pst file. To do this, the script executes:
    nircmdc waitprocess outlook.exe.

Step 3: Run ScanPST from the Command Line.

  1. Find the path to scanpst.exe on your computer:
    1. in Outlook 2003 – C:\\Program Files\Common Files\System\Mapi\1033\
    2. in Outlook 2007 – C:\Program Files\Microsoft Office\Office12\
  2. Edit autopst.bat in notepad and verify ScanPST-location=”<your path>”
  3. If your .pst/.ost files are in the default location, the command in the script – cmdscan %ScanPST-location% *.pst *.ost – will work just fine. (Otherwise, follow the instructions in readme.txt, found in the cmdscan.zip file. It will show all your file selection options).

Step 4: (optional) Open Outlook so it’s ready to go when you access your computer again.

  1. If you prefer to automatically restart Outlook after the scan, remove “REM” from the front of the “REM start outlook.exe” line.

Step 5: Create a Scheduled Task 4

  1. Start -> Programs -> Accessories -> System Tools -> Scheduled Tasks.
  2. Next -> Browse… -> select the autopst.bat file -> Next
  3. Select task frequency (i.e., Daily/Weekly) -> Next
  4. Set run time (when are you least likely to need Outlook open?
  5. …you get the idea…

Step 6: Test

  1. Double-click on the autopst.bat file or execute the newly created task to make sure things go as expected.
  1. Command Line Process Viewer/Killer/Suspender – This method first tried to gracefully shut down Outlook. If Outlook remains open after 60 seconds, the process is forced to terminate. []
  2. nircmdc is a command line only version of nircmd – this makes popup dialogs print to cmd window instead; thus, allowing us to automate processes more reliably []
  3. How to set the path in: Windows XP / Vista []
  4. How To Schedule Tasks in Windows XP []
  • djpogoff
    I appreciate your work in automating ScanPST. I'm quite curious, though, why it is that the PST files become corrupted so easily and frequently. No matter how carefully I "behave" as an Outlook user, my PST files (I typically have 4) become corrupted more than once per day.

    I'm using Outlook 2007 with 4 PST files: (1) Personal Folders - no email; (2) professional IMAP account; (3) personal IMAP account; (4) Gmail IMAP account. Is OL '07 particularly prone to corruption or is the use of IMAP (instead of POP3 or Exchange) greatly contribute to the frequency of corruption? I'm betting that, when using Exchange, corruption is less likely and less frequent. What have others found?
  • One major cause of corruption would be add-ins. And, I can say that even with Exchange, there are freqent corruption issues (i.e., errors found in the scan). I've never had my .pst file get so corrupted that it wouldn't open, but I did run into cases where performance was being impacted.
  • mtmail
    Sorry, the Outlook- Version is 2003

    If I repair the large files directly with scanpst from MS there is no problem, only when i start it with cmdscan, cmdscan works on the same computer with small files but not with the large ones.
  • mtmail
    Thanks for your fast reply.

    1) OK I have to add each file separatly, there is no wildcard allowed on a non standard pat of th pst file.

    2) It would be highly appriciated if you could check the limit, i have to repair 4 files between 15 and 19.8 GB
  • RE: 2) Does the large .pst file scan if you run scanpst manually and browse and select the file?

    The tools I use (nircmd & cmdscan) only automate the process and redirect output to scanpst. So, if scanpst doesn't process the file manually, then it won't process it via this script either.

    Also, what version of Outlook are you using?
  • mtmail
    Hi, I have two questions regarding your cool tool.

    1) how can I add multiple files in an custom .pst path, e.g. cmdscan d:\email\*.pst
    This command does not work, is there a way to specify a command to scan multiple files at non default path?

    2) When I am trying to scan large .pst files e.g. 15GB the cmdscan tells me that the file is not found or is in use, the specified pathh is 100% correct (copy&paste) and Ourlook is closed.
  • 1) Edit the batch file to add the full static paths in place of *.pst. So it would look like:
    cmdscan %ScanPST-location% "C:\email\primaryfile.pst" "D:\email\folder\hugearchive.pst"

    2) I've never had to deal with a .pst this large! I'll look into it and see if I can find out what the .pst size limit is for the utility.
  • anonymous
    This is a great site, and I really found that autopst was helpful to me, since I have multiple PST files. I seem to get errors quite often, so I run SCANPST alal the time, to control the errors.

    My modified autopst.bat file is below. One question: How can I use nircmdc (or some other program) to change the priority of SCANPST.EXE from "normal" to "high?"

    REM Automating the Outlook ScanPST Repair
    REM scripted by Anish H. Patel (http://www.opindian.com)


    rem how do I change priority for sCANST?
    rem added separate cmdscan line for each PST file
    rem why isn't cmdscan producing BAK file for each scanned PST?

    CLS
    @echo on

    set ScanPST-location="C:\Program Files\Common Files\System\MSMapi\1033\scanpst.exe"


    REM gracefully close Outlook so that the repair scan can run
    rem ... but first stop (kill) the Win Mobile sync application (which forces Outlook to stay open)
    nircmdc killprocess wcescomm.exe


    nircmdc closeprocess outlook.exe
    nircmdc waitprocess outlook.exe


    REM Run Inbox Repair
    c:
    cd "C:\Program Files\Common Files\System\MSMapi\1033"

    rem we need to remove all the outlook.bak files
    rem del d:\outlook\*.bak

    cmdscan d:\email\Outlook.pst
    cmdscan d:\email\OL2.pst
    cmdscan d:\email\OL3.pst
    cmdscan d:\email\other.pst
  • I like the waitprocess mod (don't know why I didn't use that before, but I'll edit the script/instructions to include this).

    As far as increasing the priority, I don't know of a way to do this natively in the batch script since the 'cmdscan' funtion has to complete before moving on to the next command in the script. There are a few alternatives to make this work though:

    1) My Recommendation: Use a 3rd party tool like Process Lasso to always increase the priority of certain processes. (This program is actually useful for more than just this script).

    2) Place the cmdscan command in a seperate batch file and call it. This will cause the cmdscan to run in a sepearte process and continue processing the autopst.bat file.
    Then, in the autopst file, enter the following command after the cmdscan call: "nircmdc setprocesspriority scanpst.exe high"
  • andrew
    sure it is
blog comments powered by Disqus