Wednesday, June 18, 2008

OLKAway - Remove Outlook Temp Folder At Startup

Delete the contents of the temporary Outlook folder at startup.

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=OLKaway.exe
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; This script will delete the OLKxxx or the content.outlook folder under 
; c:\documents and settings\%username%\local settings\temporary internet files\
; It will check for the presense of the OutlookSecureTempFolder entry in the registry
; starting with Outlook 2007, all the way to Outlook 2000 working backwards.
; Once found, it will delete the contents.
; 01/07/2008
; ab@nyitsupport.com
 
AutoItSetOption ("RunErrorsFatal", 0)
AutoItSetOption ("TrayIconHide",1)
 
dim $InstallPath
$InstallPath = "C:\Program Files\NYITSupport\OLKaway\"
 
Select
    case @OSVersion = "WIN_XP"
        Call ("StartSequence")
    case @OSVersion = "WIN_2000"
        $ver = RegRead("HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions", "ProductType")
        If $ver = "ServerNT" then Exit
        Call ("StartSequence")
    case Else
        Exit
EndSelect    
    
Func StartSequence()
    if $CmdLine[$CmdLine[0]] = "" then 
        call ("CleanUp")
    Else
        Select
            case $CmdLine [1] = "/uninstall"
                if not IsAdmin() then Exit
                call ("Uninstall")
                
            case $CmdLine [1] = "/install" 
                if not IsAdmin() then Exit
                if FileExists($InstallPath) then Exit
                Call ("Install")
        
            case Else
                Exit
                
        EndSelect
    EndIf
EndFunc
 
func CleanUp()
    $OSTF = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Security", "OutlookSecureTempFolder") ; Outlook 2007
    if @error then $OSTF = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Security\", "OutlookSecureTempFolder") ; Outlook 2003
    if @error then $OSTF = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Outlook\Security", "OutlookSecureTempFolder") ; Outlook XP
    if @error then $OSTF = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Outlook\Security", "OutlookSecureTempFolder") ; Outlook 2000
    DirRemove($OSTF,1)
EndFunc
        
Func Install()
    FileCopy (@ScriptFullPath, $InstallPath,8)
    ShellExecute("cacls.exe", '"' & StringLeft($InstallPath, StringLen($InstallPath)-1) & '" /e /c /g BUILTIN\Users:F')
    FileCreateShortcut($InstallPath & "OLKaway.exe", @StartupCommonDir & "\NYITSUPPORT OLKaway.lnk", $InstallPath, "", "NYITSUPPORT OLKaway")
    call ("CleanUp")
EndFunc
 
Func Uninstall()
    FileDelete (@StartupCommonDir & "\NYITSUPPORT OLKaway.lnk")
    DirRemove($InstallPath,1)
EndFunc

3 comments:

Pavel said...

This is what I need for the issues we are having at our IT Help Desk. Can you provide some insight on how to compile this into an exe?

Any help would be great.

Alex said...

please download the AutoITScript software from autoitscript.com
Also get the scite editor on the same page.
Its a free development environment. paste the code into the file and go to tools, compile.

Alex said...

I have just posted a new version of the script.
http://nyitsupport.blogspot.com/2009/10/olkaway-now-with-vista-support.html