Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Automatically compact all Microsoft Outlook PST data files using an AutoIT script
;//Compact all PST files.au3
;//Rick Upton, November 1, 2015
;//http://www.rickupton.com | http://gb.rickupton.com
;//
;//This AutoIT script is a slightly modified version of code posted here: http://superuser.com/questions/836758/bulk-compaction-of-700gb-of-pst-files
;//The purpose of this code is to automatically compact all Outlook PST files on a Windows PC.
;//
;//Using a PowerShell script, open the Mail control panel and then run this script using the following two commands:
;//Show-ControlPanelItem Mail*
;//Start-Process "C:\Compact all PST files.au3" -Wait
;//
#include <GUIListView.au3>
SplashTextOn("Automated compaction of Outlook files in process", "DO NOT TOUCH THE COMPUTER WHILE THIS IS RUNNING.", 400, 80)
Opt("WinTitleMatchMode", 4)
WinWait("Mail Setup - Outlook", "Setup e-mail accounts and dire")
ControlClick("Mail Setup - Outlook", "Setup e-mail accounts and dire", "Button2")
WinWait("Account Settings", "AcctMgr Tab")
;//Gets list of Data files listed
$sTitle = "Account Settings"
$hWnd = WinGetHandle($sTitle)
If @error Then
MsgBox(0, "Error", "Unable to find window")
EndIf
WinActivate($hWnd)
$hlist = ControlGetHandle($hWnd, "", "[CLASS:SysListView32; INSTANCE:2]")
If @error Then Exit
$arraycount = _GUICtrlListView_GetItemCount($hlist)
Local $ltext[$arraycount]
$i = 0
Do
$ltext[$i] = _GUICtrlListView_GetItemText($hlist, $i)
$i = $i + 1
Until $i = $arraycount
;//Goes into each listed Data file and compacts them
$b = 0
Do
_GUICtrlListView_ClickItem($hlist, $b, "left", False, 2)
Sleep(1000)
WinWaitActive("Outlook Data File")
ControlClick("Outlook Data File", "", "[CLASS:Button; INSTANCE:2]") ; click Compact Now
Sleep(1200)
If WinExists("Compact Now") Then WinWaitClose("Compact Now")
WinClose("Outlook Data File")
$b = $b + 1
Until $b = $arraycount
WinClose("Outlook Data Files")
WinClose("Account Settings")
WinClose("Mail Setup - Outlook")
SplashOff()
Exit
@Ashmal123
Copy link

Ashmal123 commented Feb 2, 2017

Here is another complete tool to compress PST File with multiple different options.
Download free PST Compress tool and get rid of the large heavy file in just a few simple steps.
For free version visit: https://www.sysinfotools.com/recovery/pst-compress.php

@Pauls83
Copy link

Pauls83 commented Oct 29, 2020

Does this work the same way as pressing the compact now button in outlook?

@rickupton
Copy link
Author

rickupton commented Jul 7, 2022

Does this work the same way as pressing the compact now button in outlook?

Yes, this script automates the process of pressing "Compact Now" for each data file.

@henrybill9
Copy link

henrybill9 commented Jul 12, 2022

Softaken PST Compress software safely reduces the size of large Outlook PST data files by compressing them. It is extremely well designed to compact extra-large Outlook PST data files to avoid any type of corruption and to save space in the hard drive of the system. This application does not alter the contents of Outlook PST files. Compress Outlook PST tool enables a user-friendly GUI appearance with advanced algorithms. This utility supports all MS Outlook and Windows OS versions.

Visit here:- https://www.softakensoftware.com/compact-pst.html

@styxadmin
Copy link

styxadmin commented Jul 12, 2022

Softaken PST Compress software safely reduces the size of large Outlook PST data files by compressing them. It is extremely well designed to compact extra-large Outlook PST data files to avoid any type of corruption and to save space in the hard drive of the system. This application does not alter the contents of Outlook PST files. Compress Outlook PST tool enables a user-friendly GUI appearance with advanced algorithms. This utility supports all MS Outlook and Windows OS versions.

Visit here:- https://www.softakensoftware.com/compact-pst.html

Why don't you bugger off you shill!

@styxadmin
Copy link

styxadmin commented Jul 12, 2022

Here is another complete tool to compress PST File with multiple different options. Download free PST Compress tool and get rid of the large heavy file in just a few simple steps. For free version visit: https://www.sysinfotools.com/recovery/pst-compress.php

Why don't you sell your software somewhere else!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment