Script de Sauvegarde

SaveProfilManuel.vbs

SaveProfilManuel.vbs

Script permettant de sauvegarder les éléments du profil utilisateur connecté (Bureau, Documents, Favoris, Téléchargements, Images, profil Firefox, signatures Outlook).

'************************************************* 'SaveProfilManuel.vbs '************************************************* 'Script permettant de sauvegarder les éléments 'du profil utilisateur connecté '************************************************* 'Creation : LPR pour Carsat Rennes '************************************************* 'v1.0 : Le 07/12/2021 '************************************************* '************************************************* 'Déclaration des variables '************************************************* Dim oShell Dim strAPPDATA, strUserProfile, strDesktop, strDocuments, strExclusionFile Dim strTelechargement, strFavoris, strFirefox, strIniFirefox, strImages Dim strDestination, strRepFirefox, strCmd, strCmd2, strCmd3 Dim TabCommande(5) Set oShell = CreateObject("WScript.Shell") Set objApp = CreateObject("shell.application") Set fso = CreateObject("Scripting.FileSystemObject") Const ForReading = 1, ForWriting = 2 strUserName = oShell.ExpandEnvironmentStrings("%USERNAME%") 'Pour le login du user strAPPDATA = oShell.ExpandEnvironmentStrings("%APPDATA%") strUserProfile = oShell.ExpandEnvironmentStrings("%USERPROFILE%") strDesktop = oShell.SpecialFolders("Desktop") strDocuments = oShell.SpecialFolders("MyDocuments") strTelechargement = strUserProfile & "\Downloads" strFavoris = strUserProfile & "\Favorites" strImages = strUserProfile & "\Pictures" strFirefox = strAPPDATA & "\Mozilla\Firefox" strIniFirefox = strFirefox & "\profiles.ini" strOutlook = strAPPDATA & "\Microsoft\Signatures" strDestination = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) strDestination = strDestination & "\" & strUserName & "\" strExclusionFile = " /XF ""Badgeage.URL"" ""Calculatrice.lnk"" ""Info Poste.lnk"" ""Internet.url"" ""Mes Applications Secours.url"" ""Microsoft*.lnk"" ""Ordinateur.lnk"" ""Serveur d'Impression.lnk""" 'On minimize toutes les fenetres objApp.MinimizeAll '************************************************* 'Création d'un tableau pour les commandes '************************************************* TabCommande(0) = "robocopy.exe """ & strDesktop & """ """ & strDestination & "Bureau"" /MIR " & strExclusionFile TabCommande(1) = "robocopy.exe """ & strDocuments & """ """ & strDestination & "Documents"" /S /R:1 /W:5 /XD ""Ma Musique"" ""Mes Images"" ""Mes Vidéos""" TabCommande(2) = "robocopy.exe """ & strFavoris & """ """ & strDestination & "Favoris"" /MIR" TabCommande(3) = "robocopy.exe """ & strTelechargement & """ """ & strDestination & "Telechargements"" /MIR" TabCommande(4) = "robocopy.exe """ & strImages & """ """ & strDestination & "Images"" /MIR" '************************************************* 'Création du répertoire de sauvegarde '************************************************* If (fso.FolderExists(strDestination)) Then Else Set f=fso.CreateFolder(strDestination) End if '************************************************* 'Sauvegarde des répertoires '************************************************* For i = 0 to 4 oShell.Run TabCommande(i),1,True Next '************************************************* 'Sauvegarde du profil Firefox '************************************************* Set iniFirefox = fso.OpenTextFile(strIniFirefox,1) strProfilFirefox = ReadIni(iniFirefox,"Profile0","Path") strSplitFirefox = Split(strProfilFirefox,"/") If (fso.FolderExists(strDestination & "\Firefox")) Then Else Set f=fso.CreateFolder(strDestination & "\Firefox") End if strRepFirefox = strFirefox & "\Profiles\" & strSplitFirefox(1) strCmd = "robocopy.exe """ & strRepFirefox & """ """ & strDestination & "Firefox\Profiles\" & strSplitFirefox(1) & """ /MIR" strCmd2 = "xcopy.exe """ & strIniFirefox & """ """ & strDestination & "Firefox\""" oShell.Run strCmd,1,True oShell.Run strCmd2,1,True '************************************************* 'Sauvegarde des signatures Outlook '************************************************* If (fso.FolderExists(strDestination & "\Outlook")) Then Else Set f=fso.CreateFolder(strDestination & "\Outlook") End if strCmd3 = "robocopy.exe """ & strOutlook & """ """ & strDestination & "\Outlook"" /MIR" oShell.Run strCmd3,1,True msgbox "Sauvegarde de " & strUserName & " terminée.",64,"Message" Set oShell = Nothing Set fso = Nothing Set objApp = nothing wscript.quit '*********************************************************** 'LES FONCTIONS '*********************************************************** Function ReadIni(iniFile,section,key) ' renvoie la valeur de la clé de la section
de l'objet fichier ouvert en lecture Dim iniText ' Initialisation des objets regexp ' peut être déplacé dans le code principal en cas d'appels successifs Set reg = New RegExp Set regSub = New RegExp reg.IgnoreCase = True regSub.IgnoreCase = True ' lecture du fichier ini et fermeture iniText = iniFile.ReadAll iniFile.Close ' lecture de la clé spécifique de la section reg.Pattern = "\[" & section & "\]([^\[]+)":regSub.Pattern = "\b" & key & " *= *([^;\f\n\r\t\v]+)" On Error Resume Next ReadIni = regSub.Execute(reg.Execute(iniText).Item(0).SubMatches(0)).Item(0).SubMatches(0) If Err.Number = 5 then ReadIni = False End Function