Jump to content

Recommended Posts

I'm writing Outlook pst cleaner and now I'm stuck. Compiled script is crashing with OS crash message. When I tryied to run script from editor it's exiting itself (mabye it's some type of crash?) always when it's processing on 4-rd pst file. Here is my code:

#include <OutlookEX.au3>
#include <Date.au3>
#include <File.au3>
#include <Array.au3>

_cleanOutlook("Administrator")
_cleanOutlook("Admin")


Exit

Func _cleanOutlook($user)

    $foldery = "Wiadomości-śmieci#?SPAM#?Junk E-mail#?Elementy usunięte#?Deleted Items"
    $tab_folderow = StringSplit($foldery, "#?", 1)

    $tab_pst = _FileListToArrayRec("c:\users\" & $user, "*.pst", 1+4+8, 1, 0, 2)
;~  _ArrayDisplay($tab_pst)

    For $d = 1 To UBound($tab_pst) -1 Step +1

        $outlook = _OL_Open(True)
        _OL_Close($outlook, True)

        $outlook = _OL_Open()

        Local $aStores = _OL_StoreGet($outlook)
    ;~      _ArrayDisplay($aStores)
        For $i = 1 to $aStores[0][0]
            If $aStores[$i][4] = True Then
    ;~          ConsoleWrite(@CRLF & "zamykam pst 2")
                _OL_PSTClose($outlook,$aStores[$i][0])
            EndIf
        Next

;~      _OL_PSTAccess($outlook, "C:\Users\Administrator\Desktop\cos.pst")
        _OL_PSTAccess($outlook, $tab_pst[$d])

        ConsoleWrite(@CRLF & $tab_pst[$d])
;~      $tab_struktury = _OL_FolderTree($outlook, "*", 10)
;~      If @error Then
;~          ContinueLoop
;~      EndIf
;~      _ArrayDisplay($tab_struktury)

        $tab_ktory_pst = _OL_PSTGet($outlook)
;~          _ArrayDisplay($tab_ktory_pst)
        For $a = 0 To UBound($tab_ktory_pst) -1 Step +1

            If $tab_ktory_pst[$a][2] = $tab_pst[$d] Then
;~                  MsgBox(0, "", $tab_ktory_pst[$a][0])
                $nazwa_bazy_pst = $tab_ktory_pst[$a][0]
            EndIf

        Next

;~      MsgBox(0, "", UBound($tab_folderow))
;~      _ArrayDisplay($tab_folderow, $tab_pst[$d])

        ConsoleWrite(@CRLF & "przed while")

        $a = 0

        While $a < 2

            ConsoleWrite(@CRLF & "while 1")

            For $b = 1 To UBound($tab_folderow) -1 Step +1

                ConsoleWrite(@CRLF & "for 1")

                $tab_struktury = _OL_FolderTree($outlook, $nazwa_bazy_pst)
;~              _ArrayDisplay($tab_struktury, $nazwa_bazy_pst)

;~              $folder = _OL_FolderAccess($outlook, StringTrimLeft($tab_struktury[0], 2) & "\" & $tab_folderow[$b])
                $folder = _OL_FolderAccess($outlook, $nazwa_bazy_pst & "\" & $tab_folderow[$b])
;~              ConsoleWrite(@CRLF & "eeee")
                If @error Then
;~                  MsgBox(0, "", "\\" & $nazwa_bazy_pst & "\" & $tab_folderow[$b] & @CRLF & @error)
                    ConsoleWrite(@CRLF & "przechodze do kolejnego " & $b+1)
                    ContinueLoop
                EndIf
;~              _ArrayDisplay($folder, $nazwa_bazy_pst)

                ConsoleWrite(@CRLF & $tab_folderow[$b])

                If $tab_folderow[$b] = "Deleted Items" Or $tab_folderow[$b] = "Elementy usunięte" Then

                    ConsoleWrite(@CRLF & "usuwam kosze")
                    _OL_FolderDelete($outlook, $folder[1], 1)
                    _OL_FolderDelete($outlook, $folder[1], 2)
                    _OL_FolderDelete($outlook, $folder[1], 3)
                    _OL_FolderDelete($outlook, $folder[1], 4)
;~                  _OL_FolderDelete($outlook, $folder[1], 5)

                EndIf

                If $a = 0 Then

                    $tab_maile = ""

                    $data_dzis = @YEAR & "/" & @MON & "/" & @MDAY & " 00:00"
        ;~          $data_dzis = "2017/01/31 00:00"
                    $data_szukana = _DateAdd("D", "-3", $data_dzis)

                    $tab_maile = _OL_ItemFind($outlook, $folder[1], $olMail, "[Received]<'" & StringReplace($data_szukana, "/", "-") & "'", "", "", "EntryID", "", 1)
                    If @error Then
                        ContinueLoop
                    EndIf
        ;~          If UBound($tab_maile) > 1 Then
        ;~              _ArrayDisplay($tab_maile)
        ;~          EndIf

                    If UBound($tab_maile) > 1 Then

                        For $c = 1 To UBound($tab_maile) -1 Step +1

;~                          ConsoleWrite(@CRLF & "usuwam stare maile")
                            _OL_ItemDelete($outlook, $tab_maile[$c][0], "", False)

                        Next

                    EndIf

                EndIf

            Next


            $a = $a + 1

        WEnd


;~      ConsoleWrite(@CRLF & "pokazuje")
;~      $folder[1].Display
        $olFolderInbox.Display

;~      _OL_PSTClose($outlook, $olFolderInbox)
;~      If @error Then
;~          MsgBox(0, "", @error)
;~      EndIf

        Local $aStores = _OL_StoreGet($outlook)
;~      _ArrayDisplay($aStores)
        For $i = 1 to $aStores[0][0]
            If $aStores[$i][4] = True Then
;~              ConsoleWrite(@CRLF & "zamykam pst 1")
                _OL_PSTClose($outlook,$aStores[$i][0])
            EndIf
        Next

        ;_OL_PSTClose($outlook, $folder[1])

        _OL_Close($outlook, True)
        If @error Then
            MsgBox(0, "", @error)
        EndIf

        ConsoleWrite(@CRLF & "zamykam")

        ProcessWaitClose("outlook.exe", 30)

        ProcessClose("outlook.exe")

    Next

EndFunc

 

Outlook and OS is updated. I'm usinn OutlooEX in ver. 1.3.1.0

Any ideas? :)

 

Link to post
Share on other sites

Just a few questions:

  • Why do you Open, Close and then Reopen Outlook in the loop?
  • Why do you call _OL_FolderDelete multiple times? Simply use $iFlags = 0 to delete the folder, all items and all subfolders.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

Only call _OL_Open once and move it outside the main loop and close Outlook before you exit the function.
To only delete the items set $iFlag = 2 (does not delete any folders or subfolders - just items)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

Moving _OL_Open enhances performance.
Correct.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

Please post the messages you get when running the script from SciTE.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

Sure. Here you are:

Quote

>"C:\Program Files\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\Administrator\Desktop\outlook.au3" /UserParams    
+>12:18:45 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v.3.7.3.0   Keyboard:00000415  OS:WIN_7/Service Pack 1  CPU:X86 OS:X86  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files\AutoIt3\SciTE   UserDir => C:\Users\Administrator\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Administrator\AppData\Local\AutoIt v3\SciTE
>Running AU3Check (3.3.14.2)  from:C:\Program Files\AutoIt3  input:C:\Users\Administrator\Desktop\outlook.au3
+>12:18:46 AU3Check ended.rc:0
>Running:(3.3.14.2):C:\Program Files\AutoIt3\autoit3.exe "C:\Users\Administrator\Desktop\outlook.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop

c:\users\Administrator\Documents\Pliki programu Outlook\Outlook.pst
przed while
while 1
for 1
Wiadomoœci-œmieci
for 1
przechodze do kolejnego 3
for 1
przechodze do kolejnego 4
for 1
Elementy usuniête
usuwam kosze
for 1
przechodze do kolejnego 6
while 1
for 1
Wiadomoœci-œmieci
for 1
przechodze do kolejnego 3
for 1
przechodze do kolejnego 4
for 1
Elementy usuniête
usuwam kosze
for 1
przechodze do kolejnego 6
c:\users\Administrator\Documents\Pliki programu Outlook\test@cos.cl.pst
przed while
while 1
for 1
przechodze do kolejnego 2
for 1
przechodze do kolejnego 3
for 1
Junk E-mail
for 1
Elementy usuniête
usuwam kosze
for 1
przechodze do kolejnego 6
while 1
for 1
przechodze do kolejnego 2
for 1
przechodze do kolejnego 3
for 1
Junk E-mail
for 1
Elementy usuniête
usuwam kosze
for 1
przechodze do kolejnego 6
c:\users\Administrator\Documents\Pliki programu Outlook\test@firmaadams.ex.pst
przed while
while 1
for 1
Wiadomoœci-œmieci
for 1
przechodze do kolejnego 3
for 1
przechodze do kolejnego 4
for 1
przechodze do kolejnego 5
for 1
przechodze do kolejnego 6
while 1
for 1
przechodze do kolejnego 2
for 1
przechodze do kolejnego 3
for 1
przechodze do kolejnego 4
for 1
przechodze do kolejnego 5
for 1
przechodze do kolejnego 6
c:\users\Administrator\Documents\Outlook Files\Outlook.pst
przed while
while 1
for 1!>12:18:55 AutoIt3.exe ended.rc:-1073741819
+>12:18:55 AutoIt3Wrapper Finished.
>Exit code: 3221225477    Time: 11.3

 

 

Link to post
Share on other sites

When you search the forum for "1073741819" (mind the removed -) then you will get a lot of hits. Seems to be a problem with how your script is coded.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

Most of the time it is a problem with the parameters you provide. Can you make sure that all three variables contain valid data?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

When I added

If $tab_ktory_pst = "" Then
                    ConsoleWrite(@CRLF & $nazwa_bazy_pst & "\" & $tab_folderow[$b])
                EndIf

before

$folder = _OL_FolderAccess($outlook, $nazwa_bazy_pst & "\" & $tab_folderow[$b])

it's running fine. How to explain it?

 

Update:

After few compilations it's not running properly again. Strange is that I did not any changes in code...

Variables what I passed to  _OL_FolderAccess are: dh14@firmaadams.pl\SPAM

Variables are correct.

 

Update 15:20:

Ok, I get it! This part of code causes crash :

_OL_FolderDelete($outlook, $folder[1], 1)
                    _OL_FolderDelete($outlook, $folder[1], 2)
                    _OL_FolderDelete($outlook, $folder[1], 3)
                    _OL_FolderDelete($outlook, $folder[1], 4)
                    _OL_FolderDelete($outlook, $folder[1], 5)

Calling _OL_FolderDelete multiple times in this same loop, on this same folder causing crash.

Problem solved :)

Edited by Smigacznr1
update
Link to post
Share on other sites

Can you please explain in words what you try to achieve with your script?
As far as I understand you want to

  • Process all PST files in a folder
  • empty the "deleted items" folder (or how it is named in your language)
  • for all other folders you want to delete all items older x days.

Question:

  • Why do you do this two times (While $a < 2)?
  • Why do you close all PST stores in a loop? Couldn't you just close all of them when starting the script and then process each PST file in a loop?

Suggestions:

  • Access the default folders ("deleted items", "Junk" ...) not by name but by foldertype. So your script becomes language independant.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites
On 24.03.2017 at 3:33 PM, water said:

Can you please explain in words what you try to achieve with your script?
As far as I understand you want to

  • Process all PST files in a folder
  • empty the "deleted items" folder (or how it is named in your language)

That's right.

On 24.03.2017 at 3:33 PM, water said:

Question:

  • Why do you do this two times (While $a < 2)?

I thought that elements deleted from any folder are moved to trash folder, not deleted permanently. But now i removed it and added purge default trash folder at the end of loop.

On 24.03.2017 at 3:33 PM, water said:
  • Why do you close all PST stores in a loop? Couldn't you just close all of them when starting the script and then process each PST file in a loop?

I don't want to leave outlook on Administrator profile with all user files connected to it ;)

Idea is to clean outlook files in whole organization because users don't care about their profiles...

On 24.03.2017 at 3:33 PM, water said:

Suggestions:

  • Access the default folders ("deleted items", "Junk" ...) not by name but by foldertype. So your script becomes language independant.

Good idea, I added it to the end of loop. But we have in our organization outlook files with folders in another languages ex. folder trash in english and polish, so I need to select excatly folder anyway....

Your suggestions are helpful, thanks.

 

Script is crashing again now. For now i have no idea what is wrong. Mabye could you take a look again?

 

Link to post
Share on other sites

Will check as soon as I find some spare time - might take a few days.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

Here you are updated script:

#include <OutlookEX.au3>
#include <Date.au3>
#include <File.au3>
#include <Array.au3>

_cleanOutlook("Administrator")

_cleanOutlook("Admin")

Exit

Func _cleanOutlook($user)

    $foldery = "Wiadomości-śmieci#?SPAM#?Junk E-mail#?Elementy usunięte#?Deleted Items"
    $tab_folderow = StringSplit($foldery, "#?", 1)
    
    $tab_pst = _FileListToArrayRec("c:\users\" & $user, "*.pst", 1 + 4 + 8, 1, 0, 2)

    $outlook = _OL_Open()
    
    Local $aStores = _OL_StoreGet($outlook)
    For $i = 1 To $aStores[0][0]
        _OL_PSTClose($outlook, $aStores[$i][0])
    Next
    
    For $d = 1 To UBound($tab_pst) - 1 Step +1

        _OL_PSTAccess($outlook, $tab_pst[$d])
        If @error Then
            ContinueLoop
        EndIf
        ConsoleWrite(@CRLF & $tab_pst[$d])
        $tab_ktory_pst = _OL_PSTGet($outlook)
        If @error Then
            ContinueLoop
        EndIf

        For $a = 0 To UBound($tab_ktory_pst) - 1 Step +1
            If $tab_ktory_pst[$a][2] = $tab_pst[$d] Then
                $nazwa_bazy_pst = $tab_ktory_pst[$a][0]
            EndIf
        Next

        ConsoleWrite(@CRLF & "przed for 1")
        
        For $b = 1 To UBound($tab_folderow) - 1 Step +1
        
            ConsoleWrite(@CRLF & "for 1")

            If $tab_pst[$d] = "c:\users\Administrator\Desktop\japierdo.pst" Then
                ConsoleWrite(@CRLF & $nazwa_bazy_pst & "\" & $tab_folderow[$b])
                MsgBox(0, "", $nazwa_bazy_pst & "\" & $tab_folderow[$b])
            EndIf
            
            $folder = _OL_FolderAccess($outlook, $nazwa_bazy_pst & "\" & $tab_folderow[$b])
            If @error Then
                ConsoleWrite(@CRLF & "przechodze do kolejnego " & $b + 1)
                ContinueLoop
            EndIf

            ConsoleWrite(@CRLF & $tab_folderow[$b])
            
            If $tab_folderow[$b] = "Deleted Items" Or $tab_folderow[$b] = "Elementy usunięte" Then
                ConsoleWrite(@CRLF & "usuwam kosze")
                _OL_FolderDelete($outlook, $folder[1], 5)
                ContinueLoop
            EndIf
            
            $tab_maile = ""
            $data_dzis = @YEAR & "/" & @MON & "/" & @MDAY & " 00:00"
            $data_szukana = _DateAdd("D", "-3", $data_dzis)
            $tab_maile = _OL_ItemFind($outlook, $folder[1], $olMail, "[Received]<'" & StringReplace($data_szukana, "/", "-") & "'", "", "", "EntryID", "", 1)
            If @error Then
                ContinueLoop
            EndIf

            If UBound($tab_maile) > 1 Then
                For $c = 1 To UBound($tab_maile) - 1 Step +1
                    _OL_ItemDelete($outlook, $tab_maile[$c][0], "", False)
                Next
            EndIf
            
            $folder = _OL_FolderAccess($outlook, $nazwa_bazy_pst & "\" & $olFolderJunk)
            If Not @error Then
                $tab_maile = ""
                $tab_maile = _OL_ItemFind($outlook, $folder[1], $olMail, "[Received]<'" & StringReplace($data_szukana, "/", "-") & "'", "", "", "EntryID", "", 1)
                If @error Then
                    ContinueLoop
                EndIf

                If UBound($tab_maile) > 1 Then
                    For $c = 1 To UBound($tab_maile) - 1 Step +1
                        _OL_ItemDelete($outlook, $tab_maile[$c][0], "", False)
                    Next
                EndIf
            EndIf
        Next
        
        $folder = _OL_FolderAccess($outlook, $nazwa_bazy_pst & "\" & $olFolderDeletedItems)
        If Not @error Then
            ConsoleWrite(@CRLF & "Usuwam kosz koniec")
            _OL_FolderDelete($outlook, $folder[1], 5)
        EndIf
        
        $olFolderInbox.Display
        Local $aStores = _OL_StoreGet($outlook)
        For $i = 1 To $aStores[0][0]
            _OL_PSTClose($outlook, $aStores[$i][0])
        Next
        
    Next
    
    _OL_Close($outlook, True)
    If @error Then
        MsgBox(0, "", @error)
    EndIf
    
    ConsoleWrite(@CRLF & "zamykam")
    
    ProcessWaitClose("outlook.exe", 30)
    
    ProcessClose("outlook.exe")

    Return
    
EndFunc

 

Edited by Smigacznr1
Link to post
Share on other sites

First code example: Clear specified folders of an PST by removing all items and all subfolders.

#include-once
#include "..\OutlookEX.au3"
#include <Date.au3>
#include <File.au3>
#include <Array.au3>

Global $oOL = _OL_Open()
$oPSTRoot = _OL_PSTAccess($oOL, "C:\temp\Outlook-UDF-Test.pst")
_ClearFolder($oPSTRoot, $olFolderDeletedItems)
If @error Then Exit MsgBox($MB_ICONERROR, "Error", "Could not clean folder 'Deleted items'. @error = " & @error & ", @extended = " & @extended)
_ClearFolder($oPSTRoot, $olFolderDrafts)
If @error Then Exit MsgBox($MB_ICONERROR, "Error", "Could not clean folder 'Drafts'. @error = " & @error & ", @extended = " & @extended)
_ClearFolder($oPSTRoot, $olFolderJunk)
If @error Then Exit MsgBox($MB_ICONERROR, "Error", "Could not clean folder 'Junk'. @error = " & @error & ", @extended = " & @extended)

Func _ClearFolder($oRootFolder, $iFolderType)
    Local $oStore = $oRootFolder.Store()
    Local $oFolder = $oStore.GetDefaultFolder($iFolderType)
    _OL_FolderDelete($oOL, $oFolder, 5)
    If @error Then Return SetError(@error, @extended)
EndFunc

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-11-10 - Version 1.6.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By water
      Extensive library to control and manipulate Microsoft Outlook. This UDF holds the functions to automate items (folders, mails, contacts ...) in the background. Can be seen like an API.
      There are other UDFs available to automate Outlook:
      OutlookEX_GUI: This UDF holds the functions to automate the Outlook GUI. OutlookTools: Allows to import/export contacts and events to VCF/ICS files and much more.  Threads: Development - General Help & Support - Example Scripts - Wiki
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort

      KNOWN BUGS (last changed: 2020-02-09)
      None
    • By Epulone
      For a specific requirement the outbound email are managed by an on-prem EDGE server. The EDGE re-write the local on-prem email address with another domain [exposed domain - mx record-]. Everything is working fine but we are having an issue when the internal local users are requesting an invite meeting by  Outlook calendar . In that case when the receiver accept the request invite it generate an error "domain not found". In this scenario the EDGE server is not able to rewrite also the calendar MIME request  (V-card) header inside the message so when the receiver accepts the request the reply [mechanism] will fails as will be used the email address of the local user  [domain not exposed ] and not the external one.
      I was wondering if Autoit is able to manipulate somehow the invite heade- calendar MIME (V-card))- re-witing the user email.   Thanks    
    • By Page2PagePro
      Excel VBA's IDE registers a Control-y as "cut this line of code".
      For those prone to Undo/Redo (Ctrl+Z/Ctrl+Y) you may find frustration when your code in the editor does not redo, but in fact clears your active line of code while killing redo history.
      Though not perfect, I keep this tool running in background on startup.
      The purpose is to allow Cltr+Y to act normally throughout Windows and Office and only interact *differently* with the "Microsoft Visual Basic for Applications" window that is active.
      If the Standard Menu bar exists, it'll try to click the ReDo (Blue Arrow to the right), else "Alt+e, r" keystrokes (less desired).
       
      Here's the code:
      Opt('MustDeclareVars', 1) Opt("WinTitleMatchMode", 1) HotKeySet("^y", "TriggerRedo") While 1 Sleep(10) WEnd Func TriggerRedo() ConsoleWrite("TriggerRedo()" & @CRLF) Local $title = "Microsoft Visual Basic for Applications - " Local $hWnd If WinExists($title) And WinActive($title) Then ;~ Parent Window Handle $hWnd = WinGetHandle($title) Local $aWindowPos = WinGetPos($hWnd) ;~ Control Bar Handle, Position and If Visible Local $sControlID = "[CLASS:MsoCommandBar; TEXT:Standard;]" Local $hStandardBar = ControlGetHandle($hWnd, "", $sControlID) Local $bIsVisible = ControlCommand($hWnd, "", $sControlID, "IsVisible") If $hStandardBar And $bIsVisible Then ConsoleWrite("Using Mouse Click." & @CRLF) ;~ Determine Redo button location on visible Control Bar Local $aBarPos = ControlGetPos($hWnd, "", $sControlID) Local $mX = $aWindowPos[0] + $aBarPos[0] + 217 + Int(23/2) Local $mY = $aWindowPos[1] + $aBarPos[1] + 27 + Int(22/2) MouseClick("Left", $mX, $mY, 1, 0) Else ConsoleWrite("Using VBA Send Keys." & @CRLF) $sControlID = "[CLASS:MsoCommandBar; TEXT:Menu Bar;]" Local $hMenuBar = ControlGetHandle($hWnd, "", $sControlID) ControlSend($hWnd, "", $hMenuBar, "!e") ;~ Send("r") $sControlID = "[CLASS:MsoCommandBarPopup; TEXT:Edit;]" Local $hPopupBar = ControlGetHandle($hWnd, "", $sControlID) ControlSend($hWnd, "", $hPopupBar, "r") EndIf Else ConsoleWrite("Using NATIVE Send Keys." & @CRLF) HotKeySet("^y") Send("^y") ;~ may cause "yyy..." when held HotKeySet("^y", "TriggerRedo") EndIf EndFunc ;==>TriggerRedo Hope this inspires someone.
       
       
    • By levila
      Hi guys, i would like to write a codding to send email with Bold/Italic text and new paragraph line. Example like below:
       
       
      Each line have 1 gab line.
      $oOApp = ObjCreate("Outlook.Application") $oOMail = $oOApp.CreateItem ($olMailItem) $oOMail.Save With $oOMail .To = ($to) .Subject = $subj .HTMLBody = "HEADLINE" & "Body Text" & "this is for testing purpose" .attachments.add ($attachment) .Send EndWith  
    • By PoojaKrishna
      Hi,
      I am trying to print items from Outlook in a Citrix machine. I am printing the items into PDF files using ‘Microsoft Print to PDF option’. I am using OutlookEX.au3 for printing items.
      Everything is working fine except handling the ‘Save Print Output As’ dialog appearing while trying to print the file to PDF.
      I have set the default printer to ‘Microsoft Print to PDF’ from the control panel ( Control Panel\All Control Panel Items\Devices and Printers) and using the following method to print the item.
      _OL_ItemPrint($oOutlook, $OL_Item) ;print item I am not able to handle the ‘Save Print Output As’ dialog initiated by the print statement in the Citrix machine. The WinActive method always returns false. I have tried with ControlSetText, ControlClick and Send methods also.
      Can anyone please help?
      Func _SavePDF($sFilePath) WinActivate ( "Save Print Output As", "") WinWaitActive ( "Save Print Output As", "",5 ) If WinActive("Save Print Output As") Then sleep(500) Send($sFilePath) sleep(500) Send("{ENTER}") sleep(500) EndIf EndFunc;=>_SavePDF  
×
×
  • Create New...