Automatically compact all Microsoft Outlook PST data files using an AutoIT script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;//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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why don't you sell your software somewhere else!