«•»


Automating Outlook’s Inbox Repair Tool (ScanPST)

Date September 2, 2008 : Permalink :

File-Schedule 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.exe[2] 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 Path[3] 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.
Footnotes/References:
  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[]
  • Orrin
    I got it working! Thank you. I've been looking for a solution like this!
  • JEBWHS87
    You may want to add del *.bak to the batch file. If there are backups from previous scans you will still have to click on the YES button to close/overwrite the backup files. I put a del *.bak in the batch to remove all the old backup files.
  • Gerry Storm
    Working nicely so far, thank you so much!
  • andrew
    sure it is
  • 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"
blog comments powered by Disqus