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? :)

 

Share this post


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 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I'm reopening outlook inside loop because it was my last idea to check yesterday. I thought that mabye outlook have some limitation, but  nothing changed.

I don't want to delete whole folder but everything what is inside.

Share this post


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 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Moving out _OL_Open it's not solution for my problem. It doesn't matter if it will be inside or outside loop.

To delete items in folder, all subfolders but leave folder itself I need to use flag 5, right (4+1)?

Share this post


Link to post
Share on other sites

Moving _OL_Open enhances performance.
Correct.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


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 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


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

 

 

Share this post


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 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


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 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


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

Share this post


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 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


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?

 

Share this post


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 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


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

Share this post


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 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


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

  • Similar Content

    • By nooneclose
      I was running my script and everything was working fine and then it just stopped working. 
      I got this error message:
      !>12:51:55 AutoIt3.exe ended.rc:-1073741819 +>12:51:55 AutoIt3Wrapper Finished. >Exit code: 3221225477 Time: 354.6 I looked that error up and this article (https://www.autoitscript.com/trac/autoit/ticket/2541) said it was fixed a long time ago. 
      I am using version: SciTE Version 4.1.0, how am I getting this error? (first time I got it after running my code 50+ times)
      it crashed while trying to loop through emails. 
      Full output log:
      >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" /run /prod /ErrorStdOut /in "C:\" /UserParams +>12:46:01 Starting AutoIt3Wrapper v.18.708.1148.0 SciTE v.4.1.0.0 Keyboard:00000409 OS:WIN_10/ CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE >Running AU3Check (3.3.14.5) from:C:\Program Files (x86)\AutoIt3 +>12:46:01 AU3Check ended.rc:0 >Running:(3.3.14.5): --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop Action 1: Create a connection to the outlook account at line: 192 Action 1: Finished at line: 205 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Current email has been changed from Unread to Read. at line: 238 Current email has been changed from Unread to Read. at line: 238 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 3: Store vaild E-mails at line: 258 Number of unread E-mails: 17 at line: 290 Action 3: Finished at line: 292 Current number of processed Emails is: 0 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Description. Suite not needed. at line: 2180 Action 7: Finished at line: 2186 Opening a new Chrome window. at line: 2747 Action 8: Open Web Browser at line: 2240 _WDStartup: "MicrosoftWebDriver.exe" --verbose Action 8: Finished at line: 2270 Action 9: Navigate to Work Order Tracking at line: 2281 Action 9: Finished at line: 2295 Action 10: Click on Create New Work Order at line: 2306 Action 10: Finished Action 11: Send E-mail Data to it's proper field at line: 2324 Sub-Action 3: Split Long Description at line: 2522 Sub-Action 3: Finished at line: 2576 Work Order Number: 660308 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 1 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Description. Suite not needed. at line: 2180 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Work Order Number: 660309 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 2 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Description. Suite not needed. at line: 2180 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Sub-Action 3: Split Long Description at line: 2522 Sub-Action 3: Finished at line: 2576 Work Order Number: 660310 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 3 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Description. Suite not needed. at line: 2180 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Work Order Number: 660311 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 4 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Description. Suite not needed. at line: 2180 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Work Order Number: 660312 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 5 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Description. Suite not needed. at line: 2180 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Work Order Number: 660313 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 6 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Proper Building format used. Send Location: YT6508 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Long Description. Suite not needed. at line: 1475 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Work Order Number: 660314 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 7 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Proper Building format used. Send Location: CN2116 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Long Description. Suite not needed. at line: 1475 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Sub-Action 3: Split Long Description at line: 2522 Sub-Action 3: Finished at line: 2576 Work Order Number: 660315 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 8 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Proper Building format used. Send Location: DT4905 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Work Order Number: 660316 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 9 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Proper Building format used. Send Location: YT6513 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 Young Tower has no suites! Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Sub-Action 3: Split Long Description at line: 2522 Sub-Action 3: Finished at line: 2576 Work Order Number: 660317 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 10 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Proper Building format used. Send Location: BT3310 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Long Description. Suite not needed. at line: 1475 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Sub-Action 3: Split Long Description at line: 2522 Sub-Action 3: Finished at line: 2576 Work Order Number: 660318 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 11 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Proper Building format used. Send Location: BT3411 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Description. Suite not needed. at line: 2180 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Sub-Action 3: Split Long Description at line: 2522 Sub-Action 3: Finished at line: 2576 Work Order Number: 660319 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 12 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 Action 4: Finished at line: 361 Action 5: Store E-mail's contents at line: 371 Action 5: Finished at line: 495 Action 6: Test to Skip based on location at line: 508 Proper Building format used. Send Location: DT4519 Action 6: Finished at line: 710 Action 7: Check if location needs to be a suite at line: 720 The 'Bathroom' is not mentioned in the Description. Suite not needed. at line: 2180 Action 7: Finished at line: 2186 Action 11: Send E-mail Data to it's proper field at line: 2324 Sub-Action 3: Split Long Description at line: 2522 Sub-Action 3: Finished at line: 2576 Work Order Number: 660320 Action 11: Finished at line: 2511 Change status was called at line: 2758 Sub-Action 2: Change E-mail to Read at line: 2223 Current email has been changed from Unread to Read. at line: 2226 Sub-Action 2: Finished at line: 2230 Action 16: Create New Work Order at line: 2705 Action 16: Finished at line: 2719 Current number of processed Emails is: 13 at line: 2735 Action 2: Scan for invaild E-mails at line: 215 Number of SKIPPED unread E-mails: at line: 226 Number of SKIPPED E-mails: 0 at line: 246 Action 2: Finished at line: 248 Action 4: Loop through E-mails at line: 302 !>12:51:55 AutoIt3.exe ended.rc:-1073741819 +>12:51:55 AutoIt3Wrapper Finished. >Exit code: 3221225477 Time: 354.6  
    • By nooneclose
      Here is my code: Currently it finds all the unread, subject restricted emails in the inbox and its subfolders. (finds 15 when it should only find 4)
      $aItems = _OL_ItemFind($oOutlook, $mFolder[1], $olMail, "[UnRead]=True", "Subject", "Maintenance Request", "EntryID,Subject", "", 1) I want to find the emails in the inbox but I don't want to include the emails from the inbox's sub-folders. 
    • By nooneclose
      Morning, I am having trouble moving emails to a folder under another account's inbox. 
      Here is the code I have tried so far. 
       
      ; Access the Need Human folder under HELPDESK email account Local $nhFolder = _OL_FolderAccess($oOutlook, "helpdesk@hotmail.com\Inbox\Need Human") If @error <> 0 Then Exit MsgBox(16, "GC_WO_BOT:", "Error accessing folder 'helpdesk@hotmail.com\Inbox\Need Human'. @error = " & @error & " at line: " & @ScriptLineNumber) ;_ArrayDisplay($nhFolder, "Folder Access") ;MsgBox("", "email", $aItems[1][0]) ; Move the E-mails _OL_ItemMove($oOutlook, $aItems[1][0], Default, $nhFolder[5], "Need Human") If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemMove", "Error moving specified Email. @error = " & @error & ", @extended = " & @extended & " at line: " & @ScriptLineNumber) ConsoleWrite("The current email " & $aItems[1][0] & "was just moved to: " & $nhFolder[1] & @CRLF) I get error moving specified email @error = 1, @extended = 1 
    • By nooneclose
      @water I am getting this error for the first time ever. I have run my code well over 60 times and I'm a bit confused as to why I am sometimes getting this error now. 
      Here is the code and the error message that popped up:
      $aItems = _OL_ItemFind($oOutlook, "*\Outlook-UDF-Test", $olMail, "[UnRead]=True", "", "", "EntryID,Subject", "", 1) If Not IsArray($aItems) Then Exit MsgBox(48, "", "@error = " & @error & ", @extended: " & @extended & " at line: " & @ScriptLineNumber) @error = 0, @extended: 0 at line 317
      I tried looking in the OutLookEX UDF and there is no explanation of error 0
      This is what the UDF says about "_OL_ItemFind"
      Success: One based two-dimensional array with the properties specified by $sReturnProperties Failure: Returns "" and sets @error: 1 - You have to specifiy $sSearchName AND $sSearchValue or none of them 2 - $sWarningClick not found 3 - Error accessing the specified folder. See @extended for errorcode returned by _OL_FolderAccess 4 - Error accessing specified property. @extended is set to the COM error 5 - Error filtering items. @extended is set to the COM error 1nmm - Error checking the $sReturnProperties as returned by __OL_CheckProperties. n is either 0 (property does not exist) or 1 (Property has invalid case) mm is the index of the property in error (one based) As always any help or suggestions will be greatly appreciated. 
    • By water
      Extensive library to control and manipulate Microsoft Outlook.
      Theads: Development - General Help & Support - Example Scripts - Wiki
      There is another UDF (OutlookTools) available (as a beta at the moment) to import/export contacts and events to VCF/ICS files.
      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: 2019-08-14)
      Fixed: Uploaded newly created ZIP file. Seems there was a problem with the structure of the ZIP file. Windows was unable to unpack the file.
×
×
  • Create New...