Sauvegarde profile de Windows XP ou Windows 7 (compatible Win8 et 10)

Partagez vos scripts, et vos applications AutoIt.
Règles du forum
.
Répondre
keichi
Niveau 1
Niveau 1
Messages : 3
Enregistré le : dim. 09 avr. 2017 12:00
Status : Hors ligne

Sauvegarde profile de Windows XP ou Windows 7 (compatible Win8 et 10)

#1

Message par keichi » dim. 09 avr. 2017 12:22

Bonjour

J'ai fait dans le cadre de mon travail un script qui me permet de faire une sauvegarde de profile Windows XP et Windows 7 avec fonction de barre de progression, et information sur la taille du profile une fois la sauvegarde fini. Il y a une interface qui permet de choisir entre les 2 OS. J'ai fait de manière à ce que tout tienne en un fichier compilé. Il est possible (je ne serai pas étonné^^) que le code peut être amélioré. Tout conseil est le bienvenu et libre à tout le monde de modifier à son gré le code.
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <WinAPIFiles.au3>
#include <WinAPIReg.au3>
#include <file.au3>
#include <GUIConstants.au3>




$Form1_1 = GUICreate("Laucher", 613, 431, 192, 132)
$WinXP = GUICtrlCreateButton("Windows XP", 193, 121, 227, 57)
$Win7 = GUICtrlCreateButton("Windows 7", 194, 216, 225, 57)
$Title1 = GUICtrlCreateLabel("Sauvegarde de profile Windows", 90, 51, 435, 27, BitOR($SS_CENTER,$WS_BORDER))
GUICtrlSetFont(-1, 12, 400, 0, "Comic")
GUICtrlSetTip(-1, "50")
GUISetState(@SW_SHOW)
$Title2 = GUICtrlCreateLabel("Ne pas fermer la session ou redémarrer l'ordinateur tant que la fenêtre d'état de la sauvegarde n'est pas apparu !", 90, 300, 435, 45, BitOR($SS_CENTER,$WS_BORDER))
GUICtrlSetFont(-1, 12, 400, 0, "Comic")
GUICtrlSetTip(-1, "50")
GUISetState(@SW_SHOW)



While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $WinXp





 Func ProgressCopy1($current, $destination, $UseMultiColour=0, $attrib = "-N", $overwrite = 1 ,$Run1 = 0 )

;FirstTimeRun Get original DirSize and set up Gui
If $Run1 = 0 Then
Global $OverallQty, $Overall, $source, $overallpercent, $Progress0Text, $progressbar1, $Progress1Text, $progressbar2, $Progress2Text, $LocalPercent
DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
If not FileExists ($Destination) then DirCreate ($Destination); This is why it was failing, the dir did not exist
$source = $current
If StringRight($current, 1) = '\' Then $current = StringTrimRight($current, 1)
If StringRight($destination, 1) <> '\' Then $destination = $destination & "\"
$tosearch = $current
$Overall = DirGetSize($tosearch, 1)
$OverallQty = $Overall[1]
Global $PrCopyGui = GUICreate("Copie des Fichiers", 435, 120, -1, -1, -1, 0)
$Progress0Text = GUICtrlCreateLabel("Veuillez patienter", 10, 5, 400, 20, 0)
$progressbar1 = GUICtrlCreateProgress(10, 20, 400, 20)
GUICtrlSetColor(-1, 32250)
$Progress1Text = GUICtrlCreateLabel("", 10, 44, 400, 30, 0)
$progressbar2 = GUICtrlCreateProgress(10, 80, 400, 20, 0)
$Progress2Text = GUICtrlCreateLabel("", 10, 102, 400, 20, 0)
GUISetFont(10, 600)
;$Progress2Text2 = GUICtrlCreateLabel("", 150, 62, 400, 20)
GUICtrlSetColor(-1, 32250); not working with Windows XP Style if not using windows classic style or dllcall above
GUISetState(@SW_SHOW)
GUICtrlSetData($Progress1Text, "Répertoire de travail " & $tosearch)
$Run1 = 1
EndIf

$Size = DirGetSize($current, 3)
$Qty = $Size[1]
Local $search = FileFindFirstFile($current & "\*.*")
While 1
Dim $file = FileFindNextFile($search)
If @error Or StringLen($file) < 1 Then ExitLoop
If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
$Qty -= 1
$LocalPercent = 100 - (($Qty / $Size[1]) * 100)
$OverallQty -= 1
$overallpercent = 100 - (($OverallQty / $Overall[1]) * 100)
GUICtrlSetData($Progress0Text, "Progression Totale " & Int($overallpercent) & "% Completer")
GUICtrlSetData($progressbar1, $overallpercent)
GUICtrlSetData($progressbar2, $LocalPercent)
GUICtrlSetData($Progress2Text, "Copie du Fichier " & $file)

If $useMultiColour then
GUICtrlSetColor($Progressbar2, _ChangeColour($LocalPercent))
GUICtrlSetColor($Progressbar1, _ChangeColour($OverallPercent))
EndIf

FileCopy($current & "\" & $file, $destination & StringTrimLeft($current, StringLen($source)) & "\" & $file,$overwrite)
FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
EndIf
If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
DirCreate($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file)
FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
GUICtrlSetData($Progress1Text, $current & "\" & $file)
ProgressCopy1($current & "\" & $file, $destination, $UseMultiColour, $attrib, $overwrite,1)
EndIf
WEnd
FileClose($search)
;when overall percent = 100 set end gui text, delete gui and reset run1 to 0
If $overallpercent = 100 Then
GUICtrlSetData($Progress0Text, "Progression Totale complètée à 100%")
GUICtrlSetData($progressbar1, 100)
GUICtrlSetData($progressbar2, 100)
GUICtrlSetData($Progress2Text, "Terminer !")
Sleep(500)
GUIDelete($PRCopyGui)
$Run1 = 0
EndIf
EndFunc ;==>ProgressCopy1

Func _ChangeColour($start)

$Redness = Int(255 - ($start / 100 * 512))
If $Redness < 0 Then $Redness = 0

$Greeness = Int(($start / 100 * 512) - 257)
If $Greeness < 0 Then $Greeness = 0

$Blueness = Int(255 - ($Redness + $Greeness))

Return ($Redness * 256 * 256) + ($Greeness * 256) + $Blueness

EndFunc

;définition des variable
$User = @UserName
$UserDir = @UserProfileDir
$Bureau = @DesktopDir
$Document = @MyDocumentsDir
$Favoris = @FavoritesDir
$LocalAppDir = @LocalAppDataDir
$AppDir = @AppDataDir
$save_Opst = $LocalAppDir & "\Microsoft\Outlook"
$Mozilla = $AppDir & "\Mozilla\Firefox"


ProgressCopy1($Bureau, ".\Profile\" & $User & "\Bureau", 0)
ProgressCopy1($Document, ".\Profile\" & $User & "\Documents", 0)
ProgressCopy1($Favoris, ".\Profile\" & $User & "\Favoris", 0)
ProgressCopy1($save_Opst, ".\Profile\" & $User & "\Outlook", 0)
ProgressCopy1($Mozilla, ".\Profile\" & $User & "\Mozilla", 0)
FileDelete(".\Profile\" & $User & "\outlook\*.srs")
FileDelete(".\Profile\" & $User & "\outlook\*.xml")
FileDelete(".\Profile\" & $User & "\outlook\*.dat")
DirRemove(".\Profile\" & $User & "\Mozilla\Crash Reports\", 1)

TailleProfile()
Func TailleProfile()
    Local $iSize = DirGetSize(".\Profile")
    MsgBox(0, "Etat de la sauvegarde", "La sauvegarde est terminée" & @lf & "Dossier profile de " & @UserName  & " est de  " & Round($iSize / 1024 / 1024) & " Mo")

EndFunc   ;==> TailleProfile

                 Case $Win7


Func ProgressCopy2($current, $destination, $UseMultiColour=0, $attrib = "-N", $overwrite = 1 ,$Run1 = 0 )

;FirstTimeRun Get original DirSize and set up Gui
If $Run1 = 0 Then
Global $OverallQty, $Overall, $source, $overallpercent, $Progress0Text, $progressbar1, $Progress1Text, $progressbar2, $Progress2Text, $LocalPercent
DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
If not FileExists ($Destination) then DirCreate ($Destination); This is why it was failing, the dir did not exist
$source = $current
If StringRight($current, 1) = '\' Then $current = StringTrimRight($current, 1)
If StringRight($destination, 1) <> '\' Then $destination = $destination & "\"
$tosearch = $current
$Overall = DirGetSize($tosearch, 1)
$OverallQty = $Overall[1]
Global $PrCopyGui = GUICreate("Copie des Fichiers", 435, 120, -1, -1, -1, 0)
$Progress0Text = GUICtrlCreateLabel("Veuillez patienter", 10, 5, 400, 20, 0)
$progressbar1 = GUICtrlCreateProgress(10, 20, 400, 20)
GUICtrlSetColor(-1, 32250)
$Progress1Text = GUICtrlCreateLabel("", 10, 44, 400, 30, 0)
$progressbar2 = GUICtrlCreateProgress(10, 80, 400, 20, 0)
$Progress2Text = GUICtrlCreateLabel("", 10, 102, 400, 20, 0)
GUISetFont(10, 600)
;$Progress2Text2 = GUICtrlCreateLabel("", 150, 62, 400, 20)
GUICtrlSetColor(-1, 32250); not working with Windows XP Style if not using windows classic style or dllcall above
GUISetState(@SW_SHOW)
GUICtrlSetData($Progress1Text, "Répertoire de travail " & $tosearch)
$Run1 = 1
EndIf

$Size = DirGetSize($current, 3)
$Qty = $Size[1]
Local $search = FileFindFirstFile($current & "\*.*")
While 1
Dim $file = FileFindNextFile($search)
If @error Or StringLen($file) < 1 Then ExitLoop
If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
$Qty -= 1
$LocalPercent = 100 - (($Qty / $Size[1]) * 100)
$OverallQty -= 1
$overallpercent = 100 - (($OverallQty / $Overall[1]) * 100)
GUICtrlSetData($Progress0Text, "Progression Totale " & Int($overallpercent) & "% Completer")
GUICtrlSetData($progressbar1, $overallpercent)
GUICtrlSetData($progressbar2, $LocalPercent)
GUICtrlSetData($Progress2Text, "Copie du Fichier " & $file)

If $useMultiColour then
GUICtrlSetColor($Progressbar2, _ChangeColour($LocalPercent))
GUICtrlSetColor($Progressbar1, _ChangeColour($OverallPercent))
EndIf

FileCopy($current & "\" & $file, $destination & StringTrimLeft($current, StringLen($source)) & "\" & $file,$overwrite)
FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
EndIf
If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
DirCreate($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file)
FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
GUICtrlSetData($Progress1Text, $current & "\" & $file)
ProgressCopy2($current & "\" & $file, $destination, $UseMultiColour, $attrib, $overwrite,1)
EndIf
WEnd
FileClose($search)
;when overall percent = 100 set end gui text, delete gui and reset run1 to 0
If $overallpercent = 100 Then
GUICtrlSetData($Progress0Text, "Progression Totale complètée à 100%")
GUICtrlSetData($progressbar1, 100)
GUICtrlSetData($progressbar2, 100)
GUICtrlSetData($Progress2Text, "Terminer !")
Sleep(500)
GUIDelete($PRCopyGui)
$Run1 = 0
EndIf
EndFunc ;==>ProgressCopy



;définition des variable
$User = @UserName
$UserDir = @UserProfileDir
$Bureau = @DesktopDir
$Document = @MyDocumentsDir
$Favoris = @FavoritesDir
$Image = $UserDir & "\Pictures"
$Musique = $UserDir & "\Music"
$Download = $UserDir & "\Downloads"
$Video = $UserDir & "\Videos"
$save_Opst = $UserDir & "\AppData\Roaming\Microsoft\Outlook"
$Mozilla = $UserDir & "\AppData\Roaming\Mozilla\Firefox"


ProgressCopy2($Bureau, ".\Profile\" & $User & "\Bureau", 0)
ProgressCopy2($Document, ".\Profile\" & $User & "\Documents", 0)
ProgressCopy2($Favoris, ".\Profile\" & $User & "\Favoris", 0)
ProgressCopy2($Image, ".\Profile\" & $User & "\Mes Images", 0)
ProgressCopy2($Musique, ".\Profile\" & $User & "\Musique", 0)
ProgressCopy2($Download, ".\Profile\" & $User & "\Téléchargements", 0)
ProgressCopy2($Video, ".\Profile\" & $User & "\Vidéos", 0)
ProgressCopy2($save_Opst, ".\Profile\" & $User & "\Outlook", 0)
ProgressCopy2($Mozilla, ".\Profile\" & $User & "\Mozilla", 0)
FileDelete(".\Profile\" & $User & "\outlook\*.srs")
FileDelete(".\Profile\" & $User & "\outlook\*.xml")
DirRemove(".\Profile\" & $User & "\Mozilla\Crash Reports\", 1)

TailleProfile2()
Func TailleProfile2()
    Local $iSize = DirGetSize(".\Profile")
    MsgBox(0, "Etat de la sauvegarde", "La sauvegarde est terminée" & @lf & "Dossier profile de " & @UserName  & " est de  " & Round($iSize / 1024 / 1024) & " Mo")

EndFunc   ;==> TailleProfile2


                        Exit
    EndSwitch
 WEnd

Répondre

Qui est en ligne

Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 1 invité