Code : Tout sélectionner
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\..\..\AutoIt - Icones\Terracopy.ico
#AutoIt3Wrapper_Outfile=BM'RCopy - Perso sur DD.exe
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; DESCRIPTIF SCRIPT
; MODELE DE SCRIPT : 2.25
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Dim $script_titre, $script_desc, $auteur, $maj
$script_titre="BM'RCOPY"
$script_desc="Sauvegardes fichiers avec Robocopy"
$auteur="Btd"
$maj="05/05/13"
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; FICHIERS INCLUDES ET OPTIONS AUTOIT 2.25
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include-once
#include <7Zip.au3>
#include <Array.au3>
#include <File.au3>
#include <FileListToArrayNT.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#Include <String.au3>
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; DECLARATIONS DES VARIABLES
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Dim $log_fichier="log.txt"
Dim $ori_rep, $dest_rep
Dim $stop=0
Dim $dest_delmap, $fich_nb, $Form1
Dim $date_fichier1[6], $date_fichier2[6]
Dim $_ori_rep, $_dest_rep
Dim $tab_rapport[1]
Dim $erreur=0
Dim $map_lecteur
Dim $tps_affichage=5
Dim $rapport, $rapport_mail
Dim $etoiles
Dim $rcopy_chaine
Dim $derniere_ligne_ex
; Supp fichier log robocopy
$logR="logR.txt"
If FileExists($logR) Then FileDelete($logR)
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; FONCTIONS EXIT GUI
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; Touche ESC pour sortir du programme
HotKeySet("{ESC}", "Terminate")
; Fonction Terminate
Func Terminate()
; Confirmation exit
$reponse=MsgBox(36,$script_titre,"Etes vous sûr de vouloir arrêter la sauvegarde ?")
; Si OUI
If $reponse=6 Then
; Ferme CMD
$prg_exe="cmd.exe"
_bKillprocess($prg_exe)
; Ferme robocopy
$prg_exe="robocopy.exe"
_bKillprocess($prg_exe)
; Déconnecte lecteur réseau
If $dest_delmap<>"" Then DriveMapDel($dest_delmap)
; Rapport
$msg="PROBLEME : Sauvegarde annulée par l'utilisateur"
_bMsg($msg)
$erreur=1
$stop=1
EndIf
EndFunc
; Fonction Adlib
AdlibRegister("MyAdlib")
Func MyAdlib()
$derniere_ligne=FileReadLine($logR,-1)
$reg_exp_pattern = "^\s{1,}[0-9]{1,}\s{1,}" ; Pattern (expression à rechercher)
$derniere_ligne = StringRegExpReplace($derniere_ligne, $reg_exp_pattern,"") ; Résultat dans un tableau
$reg_exp_pattern = "^\s{2,}" ; Pattern (expression à rechercher)
$derniere_ligne = StringRegExpReplace($derniere_ligne, $reg_exp_pattern,"") ; Résultat dans un tableau
$reg_exp_pattern = "\s{2,}[0-9]{1,}\s{2,}" ; Pattern (expression à rechercher)
$derniere_ligne = StringRegExpReplace($derniere_ligne, $reg_exp_pattern," ")
$derniere_ligne=StringReplace($derniere_ligne,"New File","[New]")
$derniere_ligne=StringReplace($derniere_ligne,"New Dir","[New]")
$derniere_ligne=StringReplace($derniere_ligne,"*EXTRA File","[Sup]")
$derniere_ligne=StringReplace($derniere_ligne,"*EXTRA Dir","[Sup]")
If ($derniere_ligne<>$derniere_ligne_ex) And $derniere_ligne<>"" Then
ConsoleWrite("Console : " & $derniere_ligne & @CRLF)
_GUICtrlStatusBar_Create ($Form1, 329,$derniere_ligne)
$derniere_ligne_ex=$derniere_ligne
EndIf
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
; Confirmation exit
$reponse=MsgBox(36,$script_titre,"Etes vous sûr de vouloir arrêter la sauvegarde ?")
; SI OUI
If $reponse=6 Then
; Ferme CMD
$prg_exe="cmd.exe"
_bKillprocess($prg_exe)
; Ferme robocopy
$prg_exe="robocopy.exe"
_bKillprocess($prg_exe)
; Déconnecte lecteur réseau
If $dest_delmap<>"" Then DriveMapDel($dest_delmap)
; Rapport
$msg="PROBLEME : Sauvegarde annulée par l'utilisateur"
_bMsg($msg)
$erreur=1
$stop=1
;Exit
EndIf
EndSwitch
EndFunc
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; MENU CONTEXTUEL SYSTRAY
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Opt("TrayOnEventMode",1) ; Autorise clics dans systray
Opt("TrayMenuMode",3) ; Supprime affichage "script pause" et "exit"
TraySetClick(9) ; Only secondary mouse button will show the tray menu.
$exititem = TrayCreateItem("Quitter",-1,-1,0)
TrayItemSetOnEvent(-1,"ExitScript")
TraySetState()
; MSG SYSTRAY
Func ExitScript()
; Confirmation exit
$reponse=MsgBox(36,$script_titre,"Etes vous sûr de vouloir arrêter le programme ?")
; Si OUI
If $reponse=6 Then
; Ferme robocopy
$prg_exe="robocopy.exe"
_bKillprocess($prg_exe)
Exit
EndIf
EndFunc
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; Début script
$debut=TimerInit()
; Installation de Robocopy
FileInstall("<chemin de robocopy>\robocopy.exe", @TempDir & "\robocopy.exe", 1)
; Supp fichier log robocopy
$logR="logR.txt"
If FileExists($logR) Then FileDelete($logR)
$7zip_a_zipper=$logR
$7zip_zip=StringLeft($7zip_a_zipper,StringLen($7zip_a_zipper)-4) & ".zip"
If FileExists($7zip_zip) Then FileDelete($7zip_zip)
; Ouverture fichier log
$id=FileOpen($log_fichier, 9)
; Email destination rapport
$email="bm.autoit@gmail.com;bmounier@gmail.com"
; VERIF OUTLOOK
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
;~ Opt("WinTitleMatchMode", 2)
;~ Dim $PID
;~ $prg_exe="Outlook.exe"
;~ SplashTextOn("", "FERMETURE OUTLOOK EN COURS...", 500, 50, -1,-1,33,"", 9)
;~ $PID = ProcessExists($prg_exe)
;~ If $PID<>0 Then
;~ WinActivate("Microsoft Outlook")
;~ Send("!F")
;~ Sleep(500)
;~ WinActivate("Microsoft Outlook")
;~ Send("Q")
;~ While $PID<>0
;~ Sleep(500)
;~ $PID = ProcessExists($prg_exe)
;~ WEnd
;~ EndIf
;~ SplashOff()
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; SELECTION DESTINATION
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
$var = DriveGetDrive( "Fixed" )
$dd=""
If NOT @error Then
For $i = 1 to $var[0]
If (DriveGetLabel($var[$i])="BTD_600GO" Or DriveGetLabel($var[$i])="BTD_160GO" Or DriveGetLabel($var[$i])="BTD_320GO" Or DriveGetLabel($var[$i])="BTD_500GO") Then
$dd=StringUpper($var[$i]) & "\Sauvegardes"
$nom_dd=DriveGetLabel($var[$i])
EndIf
Next
EndIf
If $dd="" Then
msgbox(0,$script_titre,"Aucun disque dur USB de sauvegarde n'est connecté")
Exit
EndIf
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; RCOPY - DEBUT XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
$ori_rep="D:\Mes Documents" ; Sans \ final
$fich_ext="*.*"
$dest_rep=$dd & "\Mes Documents" ; Sans \ final
$fich_ext_exclus="~*.*" ; Ex : *.jpg *.gif (séparés par des espaces)
$dest_date="NON" ; OUI ou NON
$purge="OUI" ; OUI ou NON
$nom_pc=""
;$map_lecteur=_bLecteurReseau("\\","","") ; "\\IP\Rep","login","mdp"
If ($nom_pc="" Or $nom_pc=@ComputerName) Then _bRcopy($ori_rep,$fich_ext,$dest_rep,$dest_date)
; RCOPY - FIN XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; RCOPY - DEBUT XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
$ori_rep="D:\Mes Photos" ; Sans \ final
$fich_ext="*.*"
$dest_rep=$dd & "\Mes Photos" ; Sans \ final
$fich_ext_exclus="~*.*" ; Ex : *.jpg *.gif (séparés par des espaces)
$dest_date="NON" ; OUI ou NON
$purge="OUI" ; OUI ou NON
$nom_pc=""
;$map_lecteur=_bLecteurReseau("\\","","") ; "\\IP\Rep","login","mdp"
If ($nom_pc="" Or $nom_pc=@ComputerName) Then _bRcopy($ori_rep,$fich_ext,$dest_rep,$dest_date)
; RCOPY - FIN XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; Ferme fichier log
FileClose($id)
; Msg de fin des sauvegardes
GUIDelete ($Form1)
; Ecriture *** dans fichier log
_FileWriteLog($log_fichier, $etoiles)
; Affichage rapport
MsgBox(262144,$script_titre,"RAPPORT DES SAUVEGARDES" & @LF & @LF & $rapport,$tps_affichage)
; Zip rapport
$retResult = _7ZipAdd(0, $7zip_zip, $logR,0,9,0); Ne pas oublier 7-zip32.dll dans rep script
; ENVOI RAPPORT PAR MAIL
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
$mail_objet = "AUTOIT > SAUV PC PERSO > " & $nom_dd
$rapport_mail=StringReplace($rapport_mail,">>> SAUVEGARDE RÉALISÉE AVEC SUCCÈS","<font color=""#009933""><b>>>> SAUVEGARDE RÉALISÉE AVEC SUCCÈS</b></font>")
$rapport_mail=StringReplace($rapport_mail,">>> SAUVEGARDE NON RÉALISÉE","<font color=""#FF0000""><b>>>> SAUVEGARDE NON RÉALISÉE</b></font>")
$mail_texte="<FONT face=""Verdana"" color=""#000000"" size=2>" & "<br><br><b>RAPPORT DE SAUVEGARDE</b><br><br>" & $rapport_mail & "<br><br>Ordinateur : " & @ComputerName & "</font>"
; fin script
$duree = TimerDiff($debut) / 1000
Switch $duree
Case 0 To 60
$duree = Round($duree,2)
$duree = $duree & " sec"
Case 60 To 3600
$duree = $duree / 60
$duree = Round($duree,2)
$duree = $duree & " min"
Case Else
$duree = $duree / 3600
$duree = Round($duree,2)
$duree = $duree & " h."
EndSwitch
$mail_texte=$mail_texte & "<br><br><FONT face=""Verdana"" color=""#000000"" size=2>Durée d'exécution du script : " & $duree & "</font>"
If FileExists($7zip_zip) Then
$mail_pj=$7zip_zip
Else
$mail_pj=""
EndIf
$mail_A="bm.autoit@bmweb.fr"
$mail_CC=""
$mail_CCI=""
If $email<>"" Then
$mail_A=$mail_A & ";" & $email
EndIf
; Envoi mail
$rc = _INetSmtpMailCom($mail_A, $mail_objet, $mail_texte, $mail_pj, $mail_CC, $mail_CCI)
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; FONCTION RCOPY
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Func _bRcopy($_ori_rep,$_fich_ext,$_dest_rep,$_dest_date)
; Ferme robocopy
$prg_exe="robocopy.exe"
_bKillprocess($prg_exe)
; Ajout date pour rep destination
If $dest_date="OUI" Then $_dest_rep=$_dest_rep & "\" & @YEAR & "-" & @MON & "-" & @MDAY
; Rapport
$msg="SAUVEGARDE DE " & StringUpper($_ori_rep & "\" & $_fich_ext) & " VERS " & StringUpper($_dest_rep)
; Calcul nb étoiles **** pour
$etoiles=""
For $i=1 to StringLen($msg)
$etoiles=$etoiles & "*"
Next
; Ecriture Rapport
_FileWriteLog($log_fichier, $etoiles)
_FileWriteLog($log_fichier, $msg)
_ArrayAdd($tab_rapport,$msg)
; GUI
#Region ### START Koda GUI section ### Form=R:\Scripts\Autoit - BM'Tools\Sauvegardes\RCopy\Rcopy.kxf
Global $Form1 = GUICreate($script_titre, 329, 120, -1, -1)
Global $Progress1 = GUICtrlCreateProgress(8, 72, 314, 17)
Global $Label_titre = GUICtrlCreateLabel("SAUVEGARDE EN COURS", 8, 6, 314, 17, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800, 0, "Verdana")
Global $Label_ori = GUICtrlCreateLabel("De : " & $ori_rep & "\" & $fich_ext, 8, 32, 314, 17)
Global $Label_dest = GUICtrlCreateLabel("Vers : " & $dest_rep, 8, 50, 314, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
; Animation barre de progression
GUICtrlSetStyle($Progress1,0x040A)
_SendMessage(GUICtrlGetHandle($Progress1), 0x040A, True, 50)
; Ajuste lg reps
If StringLen($_ori_rep)>45 Then
$_ori_rep_affichage=StringLeft($_ori_rep,45) & "..."
Else
$_ori_rep_affichage=$_ori_rep
EndIf
If StringLen($_dest_rep)>45 Then
$_dest_rep_affichage=StringLeft($_dest_rep,45) & "..."
Else
$_dest_rep_affichage=$_dest_rep
EndIf
; Affichage des répertoires ori et dest dans GUI
GUICtrlSetData($Label_ori,$_ori_rep_affichage & "\" & $_fich_ext)
GUICtrlSetData($Label_dest,$_dest_rep_affichage)
; Test rep origine
$erreur=0
If DriveGetType ($_ori_rep)="" Then
$msg="Problème avec le répertoire d'origine (" & $_ori_rep & ")"
_bMsg($msg)
$erreur=1
EndIf
; Test rep destination
$fichier_test=$_dest_rep & "\test.txt"
$id=FileOpen($fichier_test, 10)
_FileWriteLog($fichier_test, "Test")
FileClose($id)
; Test si fichier dest existe
If Not FileExists($fichier_test) Then
; Rapport
$msg="Problème avec le répertoire de destination (" & $_dest_rep & ")"
_bMsg($msg)
$erreur=1
Else
; Supp fichier test
FileDelete($fichier_test)
EndIf
If $erreur=0 Then
If stringlen($_ori_rep)=2 Then
; Rep exclus
$rep_exclus=" /XD " & $_ori_rep & "\System Volume Information"
; Ajout \. pour ne pas copier rép courant
$_ori_rep=$_ori_rep & "\."
Else
$rep_exclus=""
EndIf
; Fichiers exclus
If $fich_ext_exclus<>"" Then $fich_ext_exclus="/XF " & $fich_ext_exclus
; Purge
If $purge="OUI" Then
$purge="/PURGE "
Else
$purge=""
EndIf
; Chaîne robocopy
$rcopy_chaine=@TempDir & '\Robocopy.exe "' & $_ori_rep & '" "' & $_dest_rep & '" ' & $_fich_ext & ' /S /NP /R:1 /W:1 '& $purge & '/LOG+:' & $logR & ' ' & $fich_ext_exclus & $rep_exclus
; Affichage dans console
ConsoleWrite(@CRLF & $rcopy_chaine & @CRLF)
; Affichage chaine rcopy
;MsgBox(0,"rcopy",$rcopy_chaine)
; Création cmd
;~ $cmd_fichier="cmd_test.cmd"
;~ $cmd_id=FileOpen($cmd_fichier, 2)
;~ FileWrite($cmd_fichier, $rcopy_chaine)
;~ FileWrite($cmd_fichier, @CRLF & "PAUSE")
;~ FileClose($cmd_id)
; Exécute robocopy
RunWait(@ComSpec & " /c " & $rcopy_chaine, "", @SW_HIDE) ; @SW_HIDE @SW_SHOW
EndIf
; Tue process robocopy si existe
$prg_exe="robocopy.exe"
_bKillprocess($prg_exe)
; Pause de 2 secondes
Sleep(2000)
; Ferme GUI
GUIDelete ($Form1)
; Déconnexte le lecteur réseau si créé
If $map_lecteur<>"" Then DriveMapDel($map_lecteur)
;~ ; Fin rapport selon état
If $erreur=0 Then
$msg=">>> SAUVEGARDE RÉALISÉE AVEC SUCCÈS"
Else
$msg=">>> SAUVEGARDE NON RÉALISÉE"
$tps_affichage=$tps_affichage*10
EndIf
_bMsg($msg)
_ArrayAdd($tab_rapport,"")
; Affichage tab rapport
;_ArrayDisplay($tab_rapport,"")
; Extrait rapport pour msgbox et remplacement @lf par retour ligne html
$rapport=""
$rapport_mail=""
For $i=1 to UBound($tab_rapport)-1
$rapport=$rapport & $tab_rapport[$i] & @LF
$rapport_mail=$rapport_mail & $tab_rapport[$i] & "<br>"
Next
EndFunc
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; FONCTION CONNEXION LECTEUR RESEAU
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Func _bLecteurReseau($_ip,$_login,$_mdp)
; Recherche lecteur libre de H à Z
For $map_lettre = 72 to 90
; Transforme lettre en lecteur
$map_lecteur_tmp=Chr($map_lettre) & ":"
; Teste si lettre déjà affectée
$retour=DriveGetType ($map_lecteur_tmp)
; Affichage lecteur en cours
;MsgBox(0,"Test", $map_lecteur_tmp & "(" & $map_lettre & ") > " & $retour)
; Mev si lecteur non affecté
if $retour="" Then
$map_lecteur=$map_lecteur_tmp
ExitLoop
EndIf
Sleep(50)
Next
; Montage lecteur réseau
$test=DriveMapAdd($map_lecteur, $_ip, 0, $_login, $_mdp)
; Test si lecteur réseau OK
If $test=0 Then
$msg="Problème avec le montage du lecteur réseau :" & @LF & $_ip
_bMsg($msg)
$erreur=1
EndIf
;MsgBox(0,"test connexion",@error & @LF & $map_lecteur & @LF & $_map_rep & @LF & $_map_login & @LF & $_map_mdp)
Return $map_lecteur
EndFunc
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; FONCTION KILL PROCESS
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
;$prg_exe="cmd.exe"
;_bKillprocess($prg_exe)
Func _bKillprocess($prg_exe)
; Récupère l'ID du process
$PID = ProcessExists($prg_exe)
; Boucle tant que process existe (instances multiples)
While $PID<>0
; Tue process si existe
If $PID Then ProcessClose($PID)
; Récupère l'ID du process
$PID = ProcessExists($prg_exe)
WEnd
EndFunc
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; FONCTION AFFICHE MSG + LOGS
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Func _bMsg($_msg)
; Affichage msg
;MsgBox(0,$script_titre, $_msg,$tps_affichage)
; Suppression retours lignes si existent
$_msg=StringReplace($_msg,Chr(10)," ")
; Ecriture dans log
_FileWriteLog($log_fichier, $_msg)
; Ajout dans rapport
_ArrayAdd($tab_rapport,$_msg)
EndFunc
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; ENVOI RAPPORT EXECUTION PAR MAIL
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Func _INetSmtpMailCom($mail_A, $mail_objet = "", $mail_texte = "", $mail_pj = "", $mail_CC = "", $mail_CCI = "")
$s_SmtpServer = "smtp.gmail.com" ; Serveur SMTP
$s_FromName = "BM'RAPPORT" ; Nom expéditeur
$s_FromAddress = "xxx@gmail.com" ; Mail expéditeur
; $mail_pj = "" ; Pièce jointe (à laisser vide si pas de PJ)
$mail_CC = "" ; Mail de copie (à laisser vide si non nécessaire)
$mail_CCI = "" ; Mail de copie invisible (à laisser vide si non nécessaire)
$s_Username = "xxx@gmail.com" ; Login compte mail
$s_Password="221EA8A16F68BE61D96728B5D641646EEE1649E277700C4F4596FB04BC46A2DBEDC4F6045B5A07A4" ;! Fonction _StringEncrypt avec clé xVYU9WHiZTju
$s_IPPort = 465 ; Port SMTP
$s_ssl = 1 ; Mettre 1 si envoi en SSL, sinon 0
$objEmail = ObjCreate("CDO.Message")
$objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
$objEmail.To = $mail_A
Local $i_Error = 0
Local $i_Error_desciption = ""
If $mail_CC <> "" Then $objEmail.Cc = $mail_CC
If $mail_CCI <> "" Then $objEmail.Bcc = $mail_CCI
$objEmail.Subject = $mail_objet
If StringInStr($mail_texte,"<") and StringInStr($mail_texte,">") Then
$objEmail.HTMLBody = $mail_texte
Else
$objEmail.Textbody = $mail_texte & @CRLF
EndIf
If $mail_pj <> "" Then
Local $S_Files2Attach = StringSplit($mail_pj, ";")
For $x = 1 To $S_Files2Attach[0]
$S_Files2Attach[$x] = _PathFull ($S_Files2Attach[$x])
If FileExists($S_Files2Attach[$x]) Then
$objEmail.AddAttachment ($S_Files2Attach[$x])
Else
$i_Error_desciption = $i_Error_desciption & @lf & 'File not found to attach: ' & $S_Files2Attach[$x]
SetError(1)
return 0
EndIf
Next
EndIf
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $s_IPPort
;Authenticated SMTP
If $s_Username <> "" Then
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
$s_Password=_StringEncrypt(0,$s_Password,"xVYU9WHiZTju",2)
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
EndIf
If $s_ssl Then
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
EndIf
;Update settings
$objEmail.Configuration.Fields.Update
; Sent the Message
$objEmail.Send
if @error then
SetError(2)
return $oMyRet[1]
EndIf
EndFunc ;==>_INetSmtpMailCom
; Com Error Handler
Func MyErrFunc()
$HexNumber = Hex($oMyError.number, 8)
$oMyRet[0] = $HexNumber
$oMyRet[1] = StringStripWS($oMyError.description,3)
ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF)
SetError(1); something to check for when this function returns
Return
EndFunc ;==>MyErrFunc
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; Supp fichier log robocopy
If FileExists("logR.txt") Then FileDelete("logR.txt")