Jump to content

Windows User files back up and restore


BrewManNH
 Share

Recommended Posts

This is a little program that I threw together to use at work when I have to back up a user's information. The program allows you to select a user from a drop down list and back up some of their files to a location of your choosing.

Where I work we have 2 types of users, Redirects which are users that are on Desktops and their Desktop and My Documents are redirected to our File Print Server, and non-redirects usually laptop users where their profiles aren't redirected (obviously). There is a set of 2 radio buttons that allow you to select Redirect or Non-Redirect, the Redirect button only backs up the user's Favorites, their Outlook contacts, and any PST files it finds in their profile folder. Non-Redirect backs those up as well as their Desktop folder and My Documents.

This has been written to be usable under Windows XP and above and uses Xcopy to perform the copy. I used Xcopy to keep the code smaller as it does the copy process and will create the folders necessary without having to go through the trouble of using a recursive file routine and arrays. My philosophy is don't reinvent the wheel; when I have a tool that does what I need it to do, why remake one that does it slower?

The program also has the option of creating a log file of the files that were copied as well as any errors that were encountered. The location that this file is saved to is the folder you select in the Input field.

I don't know how useful this will be to everyone, but it has some interesting methods for doing what it does. Please let me know if you have any issues with it.

This program uses Melba23's ExtMsgBox UDF as well as a trick I found to color the Radio buttons that AdmiralAlkex posted showing how to disable the Windows theme on a per control basis.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <ExtMsgBox.au3>
#include <EditConstants.au3>
Opt("GUIOnEventMode", 1)
Opt("Mustdeclarevars", 1)
Opt("GUICloseOnESC", 0)
Global $Backup, $Restore, $SavePath, $CopyPath[5], $Search, $LogType, $I
Global $X = 0, $NewOS, $UserName1, $Form2, $strPrompt1, $aUserList[10]
Global $ArrayItem, $Log, $LogFlag, $LogFile, $LogPath, $UserList[10]
Global $Icon, $Button, $Title, $Text, $Timeout, $Pos, $Vpos
Global $strSavePath, $Redirect, $NonRedirect, $Loop, $Success = False
Global $strLocation, $OK, $strPrompt, $Split, $sUserList[3]
If @OSVersion == "WIN_7" Or @OSVersion == "WIN_VISTA" Or @OSVersion = "WIN_2008" Then
    $NewOS = True
ElseIf @OSVersion == "WIN_XP" Then
    $NewOS = False
Else
    _MsgBox($MB_ICONexclam, "&OK", "Wrong OS", "This Script only works on Windows XP and up, it can't be used on this version of Windows.", $Timeout, $Pos, $Vpos)
    Exit
EndIf
If Not $NewOS Then
    $UserList = _FileListToArray("C:\Documents and Settings", "*.*", 2)
    For $I = 1 To $UserList[0]
        Select
            Case $UserList[$I] = "All Users"
            Case $UserList[$I] = "Default User"
            Case $UserList[$I] = "NetworkService"
            Case $UserList[$I] = "LocalService"
            Case $UserList[$I] = "Administrator"
            Case Else
                $aUserList[$X] = $UserList[$I]
                $X += 1
                If $X >= UBound($aUserList) Then
                    ReDim $aUserList[UBound($aUserList) + 10]
                EndIf
        EndSelect
    Next
Else
    $UserList = _FileListToArray("C:\Users", "*.*", 2)
    For $I = 1 To $UserList[0]
        Select
            Case $UserList[$I] = "All Users"
            Case $UserList[$I] = "Default"
            Case $UserList[$I] = "Default User"
            Case $UserList[$I] = "Public"
            Case Else
                $aUserList[$X] = $UserList[$I]
                $X += 1
                If $X >= UBound($aUserList) Then
                    ReDim $aUserList[UBound($aUserList) + 10]
                EndIf
        EndSelect
    Next
EndIf
ReDim $aUserList[$X]
$sUserList = _ArrayToString($aUserList, "|")
#Region ### START Koda GUI section ### Form=Form1
Global $Form1 = GUICreate("Backup and Restore", 629, 350, 314, 132)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetBkColor(0x4D689A, $Form1)
;  Create Ok button
GUICtrlCreateButton("&OK", 528, 70, 75, 25)
GUICtrlSetState(-1, $GUI_FOCUS)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
GUICtrlSetOnEvent(-1, "OKButton1Click")
;  Create Cancel button
GUICtrlCreateButton("Cancel", 528, 150, 75, 25)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
GUICtrlSetOnEvent(-1, "CancelButton1Click")
;Create Help button 1
GUICtrlCreateButton("Help", 528, 230, 75, 25)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
GUICtrlSetOnEvent(-1, "HelpButton1Click")
;  Create group control
Global $Group1 = GUICtrlCreateGroup("", 32, 10, 473, 320)
Global $Radio1 = GUICtrlCreateRadio("Restore?", 128, 30, 113, 17)
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($Radio1), "wstr", 0, "wstr", 0)
GUICtrlSetColor(-1, 0xff8040)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetTip(-1, "Restore user files from backup?")
Global $Radio2 = GUICtrlCreateRadio("Backup?", 312, 30, 91, 17)
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($Radio2), "wstr", 0, "wstr", 0)
GUICtrlSetColor(-1, 0xff8040)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetTip(-1, "Backup user files?")
Global $Input1 = GUICtrlCreateInput("", 80, 130, 321, 22)
GUICtrlSetTip(-1, "Drive location")
;  Create browse button
GUICtrlCreateButton("Browse", 408, 130, 43, 17)
GUICtrlSetTip(-1, "Browse for path")
GUICtrlSetOnEvent(-1, "BrowseButtonclick")
;  Create Label1
GUICtrlCreateLabel("Enter the location that your back ups are located or where you want to save them to.", 88, 80, 350, 33)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xff8040)
GUICtrlCreateLabel("Select the user to process", 88, 170, 350, 33)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xff8040)
Global $UserName = GUICtrlCreateCombo("", 80, 190, 177, 25)
GUICtrlSetTip(-1, "Select User to back up/restore!")
GUICtrlSetData(-1, $sUserList)
Global $Log = GUICtrlCreateCheckbox("Do you want to keep a log of this?", 80, 300, 209, 17)
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($Log), "wstr", 0, "wstr", 0)
GUICtrlSetColor(-1, 0xff8040)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
GUIStartGroup()
Global $Radio3 = GUICtrlCreateRadio("Redirect?", 128, 250, 113, 17)
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($Radio3), "wstr", 0, "wstr", 0)
GUICtrlSetColor(-1, 0xff8040)
GUICtrlSetTip(-1, "Only back up PST files, Favorites and Outlook contacts")
Global $Radio4 = GUICtrlCreateRadio("Non-Redirect?", 312, 250, 113, 17)
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($Radio4), "wstr", 0, "wstr", 0)
GUICtrlSetColor(-1, 0xff8040)
GUICtrlSetTip(-1, "Back up PST files, Favorites, Desktop, Documents, and Outlook contacts")
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$strPrompt = "This script is used to backup and restore the standard user folders on a Windows computer to an external drive." & @CRLF
$strPrompt &= "It will try to write to or read from the logged on user's network shared drive or any other valid drive" & @CRLF
$strPrompt &= "letter including USB drives." & @CRLF & "It is compatible with Windows XP/Vista/Windows 7/Server 2003/Server 2008."
$strPrompt &= @CRLF & "As the script is written, it will back up and restore the following folders." & @CRLF
$strPrompt &= @CRLF & """My Documents"" or ""Documents""" & @CRLF & """Desktop""" & @CRLF & """Favorites""" & @CRLF
$strPrompt &= "plus any ""*.pst"" files and Outlook contacts stored in the user's profile." & @CRLF
$strPrompt &= @CRLF & @CRLF & "When selecting the location to restore from please select the folder that the back up folder is saved to, and not the folder with the user's name."
$strPrompt &= @CRLF & @CRLF & "Example: Back ups are saved to the ""E:"" drive in the folder called ""Backups"", and the user's name is ""Jim"" (E:\Backups\Jim)"
$strPrompt &= @CRLF & "Select the folder ""E:\Backups"" and not the ""E:\Backups\Jim"" folder."
While 1
    Sleep(100)
WEnd
#Region BUR Functions
#cs
    ;===========================================================================

    Checks the chosen path to see if it exists, and if it can be
    written to if backing up, or it checks to see that the
    restore folder is where you said it was.

    ;===========================================================================
#ce
Func _CheckValidPaths()
    Local $TestFile, $Test
    If $Restore = 1 Then
        If Not FileExists($strLocation) Then
            GUISetState(@SW_HIDE)
            _MsgBox($MB_ICONexclam, "&OK", "Restore - Bad Path", "The path you selected " & "'" & $strLocation & "'" & " doesn't contain any back ups for the selected user, please try again", $Timeout, $Pos, $Vpos)
            GUISetState(@SW_SHOW)
            Return -1
        EndIf
    Else
        $TestFile = $SavePath & "\testfile"
        $Test = FileOpen($TestFile, 8)
        FileClose($Test)
        If Not FileExists($SavePath) Then
            GUISetState(@SW_HIDE)
            _MsgBox($MB_ICONexclam, "&OK", "Backup - Bad Path", "The path you selected " & "'" & $SavePath & "'" & " is an invalid path, please try again", $Timeout, $Pos, $Vpos)
            GUISetState(@SW_SHOW, $Form1)
            Return -1
        EndIf
        FileDelete($TestFile)
    EndIf
EndFunc   ;==>_CheckValidPaths
#cs
    ;===========================================================================

    _CopyFiles

    ;===========================================================================
#ce
Func _CopyFiles(ByRef $strSearch, ByRef $ArrayItem)
    Local $strRunXcopy
    $strRunXcopy = " Xcopy.exe """ & $strSearch & """ """ & $SavePath _
             & $CopyPath[$ArrayItem] & """ /y /s /h /i /c "
    If $LogFlag = 1 Then
        $strRunXcopy &= " >>" & Chr(34) & $LogPath & $LogType & Chr(34) & " 2>&1"
    EndIf
    RunWait(@ComSpec & " /c title " & $CopyPath[$ArrayItem] & "|" & $strRunXcopy, "", @SW_HIDE)
EndFunc   ;==>_CopyFiles
#cs
    ;===========================================================================




    ;===========================================================================
#ce
Func _LogFile()
    $LogFile = FileOpen($LogPath & $LogType, 2)
    FileClose($LogFile)
EndFunc   ;==>_LogFile
#cs
    ;===========================================================================

    Initiates the browse for folder function and returns the path selected by
    user.

    ;===========================================================================
#ce
Func BrowseButtonclick()
    $strSavePath = FileSelectFolder("Select a drive letter or folder, don't select My Computer", _
            "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 7)
    GUICtrlSetData($Input1, $strSavePath)
EndFunc   ;==>BrowseButtonclick
#cs
    ;===========================================================================

    Cancel button exits the script

    ;===========================================================================
#ce
Func CancelButton1Click()
    Exit
EndFunc   ;==>CancelButton1Click
#cs
    ;===========================================================================

    Calls the Help message box

    ;===========================================================================
#ce
Func HelpButton1Click()
    GUISetState(@SW_HIDE)
    $Icon = $MB_ICONINFO
    $Button = "&OK"
    $Title = "Help"
    $Text = $strPrompt
    Opt("MustDeclareVars", 0)
    _MsgBox($Icon, $Button, $Title, $Text, $Timeout, $Pos, $Vpos)
    GUISetState(@SW_SHOW, $Form1)
    Opt("MustDeclareVars", 1)
EndFunc   ;==>HelpButton1Click
#cs
    ;===========================================================================




    ;===========================================================================
#ce
;
;
Func OKButton1Click()
    Local $Test, $SavedTo
    ;   You pressed the OK button, now we are going to read your settings
    $Backup = GUICtrlRead($Radio2)
    $Restore = GUICtrlRead($Radio1)
    $SavePath = GUICtrlRead($Input1)
    $LogFlag = GUICtrlRead($Log)
    $UserName1 = GUICtrlRead($UserName)
    $Redirect = GUICtrlRead($Radio3)
    $NonRedirect = GUICtrlRead($Radio4)
    If $UserName1 <> "0" Then
        Local $Split[3], $OK
        $OK = False
        $Split = StringSplit($sUserList, "|")
        For $I In $Split
            If $UserName1 = $I Then $OK = True
        Next
        If Not $OK Then
            $Icon = $MB_ICONexclam
            $Button = "OK"
            $Title = "No user name selected"
            $Text = "You need to select the user before starting the process. Please try again"
            $Pos = $Form1
            _MsgBox($Icon, $Button, $Title, $Text, $Timeout, $Pos, $Vpos)
            Return
        EndIf
    Else
        Return
    EndIf
    Select
        Case StringLen($UserName1) = 0
            $Icon = $MB_ICONexclam
            $Button = "OK"
            $Title = "No user name selected"
            $Text = "You need to select the user before starting the process. Please try again"
            $Pos = $Form1
            _MsgBox($Icon, $Button, $Title, $Text, $Timeout, $Pos, $Vpos)
            Return
        Case $SavePath = "" ; No path selected
            GUISetState(@SW_HIDE)
            $Icon = $MB_ICONINFO
            $Button = "&OK"
            $Title = "No drive selected"
            $Text = "You need to put in the save/restore path"
            _MsgBox($Icon, $Button, $Title, $Text, $Timeout, $Pos, $Vpos)
            GUICtrlSetData($UserName, $sUserList)
            GUISetState(@SW_SHOW)
            Return
        Case StringLeft($SavePath, 1) = "C"
            $Icon = $MB_ICONexclam
            $Button = "OK"
            $Title = "Don't use C: drive"
            $Text = "You can't back up the files to the same drive you're copying from, ple" & _
                    "ase don't select the C: drive. Please try again"
            $Pos = $Form1
            _MsgBox($Icon, $Button, $Title, $Text, $Timeout, $Pos, $Vpos)
            Return
        Case StringLen($SavePath) = 1 ; Just drive letter entered?
            $SavePath &= ":\"
        Case StringRight($SavePath, 1) <> "\"
            $SavePath &= "\"
    EndSelect
    $SavePath &= $UserName1
    ;===========================================================================
    ;   Now that we know where you're saving the data to, we need to set some
    ;   variables to tell it what folders/files to back up
    ;===========================================================================
    If $Backup = 1 Then
        If $NewOS Then
            $strLocation = "C:\Users\" & $UserName1
            DirCreate($SavePath)
            $LogPath = $SavePath
            $LogType = "\Backup.log"
        Else
            $strLocation = "C:\Documents and Settings\" & $UserName1
            DirCreate($SavePath)
            $LogPath = $SavePath
            $LogType = "\Backup.log"
        EndIf
    Else
        If $NewOS Then
            $strLocation = $SavePath
            $SavePath = "C:\Users\" & $UserName1
            $LogPath = $strLocation
            $LogType = "\Restore.log"
        Else
            $strLocation = $SavePath
            $SavePath = "C:\Documents and Settings\" & $UserName1
            $LogPath = $strLocation
            $LogType = "\Restore.log"
        EndIf
    EndIf
    If Not $NewOS Then
        $CopyPath[0] = "\Favorites"
        $CopyPath[1] = "\Application Data\Microsoft\Outlook"
        $CopyPath[2] = "\*.pst"
        $CopyPath[3] = "\My Documents"
        $CopyPath[4] = "\Desktop"
    Else
        $CopyPath[0] = "\Favorites"
        $CopyPath[1] = "\AppData\Roaming\Microsoft\Outlook"
        $CopyPath[2] = "\*.pst"
        $CopyPath[3] = "\Documents"
        $CopyPath[4] = "\Desktop"
    EndIf
    $Loop = 4
    If $Redirect = 1 Then $Loop = 2
    GUISetState(@SW_HIDE)
    $Form2 = GUICreate("Copying!", 300, ($Loop + 1) * 50)
    GUISetBkColor(0x0008000, $Form2)
    GUISetState()
    For $I = 0 To $Loop
        GUICtrlCreateLabel(StringMid($CopyPath[$I], 2), 50, 20 + $I * 30, 230, 20)
        GUICtrlSetFont(-1, Default, 800, Default)
        GUICtrlSetColor(-1, 0x0FFFFFF)
    Next
    $Test = _CheckValidPaths()
    If $Test = -1 Then Return
    If $LogFlag = $GUI_CHECKED Then _LogFile()
    For $ArrayItem = 0 To $Loop
        $Search = $strLocation & $CopyPath[$ArrayItem]
        _CopyFiles($Search, $ArrayItem)
        $Search = ""
        GUICtrlCreateLabel(Chr(214), 25, 20 + $ArrayItem * 30, 10, 10)
        GUICtrlSetFont(-1, Default, 800, Default, "Symbol")
        GUICtrlSetColor(-1, 0x0FFFFFF)
        GUICtrlCreateLabel(StringMid($CopyPath[$ArrayItem], 2), 50, 20 + $ArrayItem * 30, 230, 20)
        GUICtrlSetFont(-1, Default, 800, 8)
        GUICtrlSetColor(-1, 0x0FFFFFF)
    Next
    Sleep(2000)
    GUISetState(@SW_HIDE)
    If $Backup = 1 Then
        $SavedTo = "Your files were saved to " & $LogPath
    Else
        $SavedTo = "You have restored the files for " & $UserName1
    EndIf
    _MsgBox($MB_ICONexclam, "&OK", "Done!", "We're done!" & @CRLF & @CRLF & $SavedTo, $Timeout, $Form2, $Vpos)
    GUISetState(@SW_SHOW, $Form1)
EndFunc   ;==>OKButton1Click
#EndRegion BUR Functions
#cs
    ;===========================================================================

    This calls the Extended Message Box functions written by
    Melba23 and added as an #include

    ;===========================================================================
#ce
Func _MsgBox($Icon, $Button, $Title, $Text, $iTimeout = 0, $hWin = "", $iVPos = 0)
    _ExtMsgBoxSet(1, 0, 0x02616FF, 0x02AFF6A, 10, "Consolas")
    _ExtMsgBox($Icon, $Button, $Title, $Text, $iTimeout, $hWin, $iVPos)
EndFunc   ;==>_MsgBox
Func Form1Close()
    Exit
EndFunc   ;==>Form1Close

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 1 year later...

Hello,

I love your script but I would like to know if it's possible to only backup current logged user ?

I need a script like yours for my front end user.

What I want if :

For the sources I take everyting under C:Usersblahh (current logged user)

for destination I would like to have a little popup like "please insert usb key" and when usb key is ready check the free space on it and if okay start backup ...(Full or incremental)

The user only need to put the usb key on the computer and click Go or Start when USB key is ready and they are enought free space to do bakcup

Do you know if it's difficult to do this or can you plz help me ?

Thanks

Link to comment
Share on other sites

The copy procedure is all enclosed in the OKButton1Click() function. Instead of using the information from the combobox and inputs you can get the currently logged in user's name with the @UserName macro and populate the variables using that. It's just a matter of understanding what the script is doing and modifying it to suit your needs.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 4 weeks later...

Wow, this is outstanding, congratulation Sir. This is the exact script I've been searching for and I'm iching to use it but I haven't got a clue where to insert the amendments I wish to use. I want to be able to add different folder locations to backup and restore but when I insert a new line like:

If Not $NewOS Then

$CopyPath[0] = "Favorites"

$CopyPath[1] = "Application DataMicrosoftOutlook"

$CopyPath[2] = "*.nsf"

$CopyPath[3] = "My Documents"

$CopyPath[4] = "Desktop"

$CopyPath[5] = "Application DataMicrosoftSignatures"

Else

$CopyPath[0] = "Favorites"

$CopyPath[1] = "AppDataRoamingMicrosoftOutlook"

$CopyPath[2] = "*.nsf"

$CopyPath[3] = "Documents"

$CopyPath[4] = "Desktop"

$CopyPath[5] = "AppDataRoamingMicrosoftSignatures"

EndIf

I get the following error:

Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$CopyPath[5] = "AppDataRoamingMicrosoftSignatures"

^ ERROR

I didn't thing it was going to be that easy but I've just started learning this amazing find and seek some guidance please to insert more folder locations to backup and restore.

Using OS: Windows 7 64bit.

Yours in anticipation

Ian

Link to comment
Share on other sites

change the 5 in this line to however many folders you want to back up.

Global $Backup, $Restore, $SavePath, $CopyPath[5], $Search, $LogType, $I

I also forgot that you need to change the value in line 335 to this

$Loop = 5 ; has to be one less than the number in the declaration above.
Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Outstanding Sir, I followed your expert advice, however I'm still getting an error though,

Global $Backup, $Restore, $SavePath, $CopyPath[3], $Search, $LogType, $I

If Not $NewOS Then

$CopyPath[0] = "Favorites"

$CopyPath[1] = "My Documents"

$CopyPath[2] = "Desktop"

$CopyPath[3] = "Application DataMicrosoftOutlook"

Else

$CopyPath[0] = "Favorites"

$CopyPath[1] = "Documents"

$CopyPath[2] = "Desktop"

$CopyPath[3] = "AppDataRoamingMicrosoftOutlook"

EndIf

$Loop = 2

Error:

C:UsersIanDesktopCopy User Files ProjectCopy User Folders.au3 (351) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$CopyPath[3] = "AppDataRoamingMicrosoftOutlook"

^ ERROR

Am I doing something wrong?

Thanks in advance

Ian

Link to comment
Share on other sites

  • 3 months later...

A friendly FYI

A note in regards to Win-8 Release.

If you attempt to relocate c:Users<username>AppData or any contents within, things "will" break. Mostly Metro-Apps.

A fix is expected some time in the future, likely before SP-1 but uncertain.

This changed a little between how Vista/Win-7 handled it which was also a little different in XP.

To verify what can be moved, look into the properties of the related directories/folders under c:Users<username>. If you see the option for "Locations" in the Properties, then they can be moved but use caution.

Hope it helps

WS

~ WhiteStar Magic

Always tuned to http://www.superbluesradio.com/  Tune in at http://87.117.217.41:8036/

Link to comment
Share on other sites

  • 2 months later...

When trying to compile this it gives me an error on - #include <ExtMsgBox.au3> Error: Error opening the file.

I tried commenting out the ExtMsgBox line and the ExtMsgBox stuff at the bottom of the script and then it compiles and runs but when I click OK to do the backup I get an error -

Line 2161

Error: Variable used without being declard.

There isnt a line 2161

Not sure what I need to do to make this compile and work.

Any help would be appreciated.

Link to comment
Share on other sites

  • Moderators

bonedog73,

Download the ExtMsgBox UDF file from the link my sig and put it and the StringSize UDF file in the same folder as your script. :)

If you are going to stick around with AutoIt (and why not?) then you might find the Adding UDFs to AutoIt and SciTE tutorial in the Wiki of interest. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 3 months later...

This script is AWESOME!! However, I tried it to migrate a user profile from XP to Win 7 and it did everything except for the Outlook portion. Is there a specific piece of the script to modify to make this work between XP and 7?

Thanx!!!

Link to comment
Share on other sites

  • 9 months later...

Don't mean to do a necro post but I just used this and when trying to compile it it gave me the error "variable used without being declared" on 2 variables on line 28 and line 234.

line 27 Else
line 28    _MsgBox($MB_ICONexclam, "&OK", "Wrong OS", "This Script only works on Windows XP and up, it can't be used on this version of Windows.", $Timeout, $Pos, $Vpos)
line 29    Exit
line 232 Func HelpButton1Click()
line 233    GUISetState(@SW_HIDE)
line 234    $Icon = $MB_ICONINFO

 

So I wonder if my solution should be a good one since I'm a super new scripter. i took those 2 variables and declared them global in the lines in the variables so the new code should look like this :

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile_x64=backup1.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <ExtMsgBox.au3>
#include <EditConstants.au3>
Opt("GUIOnEventMode", 1)
Opt("Mustdeclarevars", 1)
Opt("GUICloseOnESC", 0)
Global $Backup, $Restore, $SavePath, $CopyPath[5], $Search, $LogType, $I
Global $X = 0, $NewOS, $UserName1, $Form2, $strPrompt1, $aUserList[10]
Global $ArrayItem, $Log, $LogFlag, $LogFile, $LogPath, $UserList[10]
Global $Icon, $Button, $Title, $Text, $Timeout, $Pos, $Vpos
Global $strSavePath, $Redirect, $NonRedirect, $Loop, $Success = False
Global $strLocation, $OK, $strPrompt, $Split, $sUserList[3]
Global $MB_ICONexclam
Global $MB_ICONINFO
If @OSVersion == "WIN_7" Or @OSVersion == "WIN_VISTA" Or @OSVersion = "WIN_2008" Then
.... all the other lines goes here

When clicking on help NOW it works and doesn't give me this error mentionned earlier and when saving the files from a user to a network folder as well. So did i do well or made a mistake ?

Edited by bigbangnet

** Warning **Noobie ahead. handle with caution

Link to comment
Share on other sites

  • 7 months later...

Hi All,

i am very new to Autoit. I have edited some part of the script, but i need help with converting this script to robocopy as i have files that have 256 char. I notice that rodocopy does not have the function to search .PST file like xcopy, is there a way so that i can search for pst file using robocopy and without the 256 char limit? Below is the script i edited, it's kind of messy..

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=Beta
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <ExtMsgBox.au3>
#include <EditConstants.au3>

Opt("GUIOnEventMode", 1)
Opt("Mustdeclarevars", 1)
Opt("GUICloseOnESC", 0)
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)

Global $Backup, $Restore, $SavePath, $CopyPath[15], $Search, $LogType, $I
Global $X = 0, $NewOS, $UserName1, $Form2, $strPrompt1, $aUserList[10]
Global $ArrayItem, $Log, $LogFlag, $LogFile, $LogPath, $UserList[10]
Global $Icon, $Button, $Title, $Text, $Timeout, $Pos, $Vpos, $MB_ICONexclam, $MB_ICONINFO, $AboutItem, $ExitItem, $SelectedItem
Global $strSavePath, $Redirect, $NonRedirect, $Loop, $Success = False
Global $strLocation, $OK, $strPrompt, $Split, $sUserList[3]

$AboutItem = TrayCreateItem("About")
TrayItemSetOnEvent(-1,"ReadList")
TrayCreateItem("")
$ExitItem = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"ReadList")

Func ReadList()
    $SelectedItem = TrayItemGetText(@TRAY_ID)
    If $SelectedItem="Exit" Then
        Exit
    ElseIf $SelectedItem="About" Then
        Call("About")
    EndIf
EndFunc


Func About()
    MsgBox(064,"Windows User files back up and restore","Migrating of User Profile." & @CRLF & "Copyright Done By BrewManNH Edited By Chris ©2014")
EndFunc



If @OSVersion == "WIN_7" Or @OSVersion == "WIN_VISTA" Or @OSVersion = "WIN_2008" Or @OSVersion = "WIN_8" Or @OSVersion = "WIN_81" Then
    $NewOS = True
ElseIf @OSVersion == "WIN_XP" Then
    $NewOS = False
Else
    _MsgBox($MB_ICONexclam, "&OK", "Wrong OS", "This Script only works on Windows XP and up, it can't be used on this version of Windows.", $Timeout, $Pos, $Vpos)
    Exit
EndIf
If Not $NewOS Then
    $UserList = _FileListToArray("C:\Documents and Settings", "*.*", 2)
    For $I = 1 To $UserList[0]
        Select
            Case $UserList[$I] = "All Users"
            Case $UserList[$I] = "Default User"
            Case $UserList[$I] = "NetworkService"
            Case $UserList[$I] = "LocalService"
            Case $UserList[$I] = "Administrator"
            Case Else
                $aUserList[$X] = $UserList[$I]
                $X += 1
                If $X >= UBound($aUserList) Then
                    ReDim $aUserList[UBound($aUserList) + 10]
                EndIf
        EndSelect
    Next
Else
    $UserList = _FileListToArray("C:\Users", "*.*", 2)
    For $I = 1 To $UserList[0]
        Select
            Case $UserList[$I] = "All Users"
            Case $UserList[$I] = "Default"
            Case $UserList[$I] = "Default User"
            Case $UserList[$I] = "Public"
            Case Else
                $aUserList[$X] = $UserList[$I]
                $X += 1
                If $X >= UBound($aUserList) Then
                    ReDim $aUserList[UBound($aUserList) + 10]
                EndIf
        EndSelect
    Next
EndIf
ReDim $aUserList[$X]
$sUserList = _ArrayToString($aUserList, "|")
#Region ### START Koda GUI section ### Form=Form1
Global $Form1 = GUICreate("Backup and Restore", 629, 350, 314, 132)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetBkColor(0x4D689A, $Form1)
;  Create Ok button
GUICtrlCreateButton("&OK", 528, 70, 75, 25)
GUICtrlSetState(-1, $GUI_FOCUS)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
GUICtrlSetOnEvent(-1, "OKButton1Click")
;  Create Cancel button
GUICtrlCreateButton("Cancel", 528, 150, 75, 25)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
GUICtrlSetOnEvent(-1, "CancelButton1Click")
;Create Help button 1
GUICtrlCreateButton("Help", 528, 230, 75, 25)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
GUICtrlSetOnEvent(-1, "HelpButton1Click")
;  Create group control
Global $Group1 = GUICtrlCreateGroup("", 32, 10, 473, 320)
Global $Radio1 = GUICtrlCreateRadio("Restore?", 128, 30, 113, 17)
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($Radio1), "wstr", 0, "wstr", 0)
GUICtrlSetColor(-1, 0xff8040)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetTip(-1, "Restore user files from backup?")
Global $Radio2 = GUICtrlCreateRadio("Backup?", 312, 30, 91, 17)
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($Radio2), "wstr", 0, "wstr", 0)
GUICtrlSetColor(-1, 0xff8040)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetTip(-1, "Backup user files?")
Global $Input1 = GUICtrlCreateInput("", 80, 130, 321, 22)
GUICtrlSetTip(-1, "Drive location")
;  Create browse button
GUICtrlCreateButton("Browse", 408, 130, 43, 25)
GUICtrlSetTip(-1, "Browse for path")
GUICtrlSetOnEvent(-1, "BrowseButtonclick")
;  Create Label1
GUICtrlCreateLabel("Enter the location that your back ups are located or where you want to save them to.", 88, 80, 350, 33)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xff8040)
GUICtrlCreateLabel("Select the user to process", 88, 190, 350, 33)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xff8040)
Global $UserName = GUICtrlCreateCombo("", 80, 210, 177, 25)
GUICtrlSetTip(-1, "Select User to back up/restore!")
GUICtrlSetData(-1, $sUserList)
GUICtrlCreateLabel("* Leave Blank for Current User.", 83, 239, 350, 33)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF8040)
Global $Log = GUICtrlCreateCheckbox("Do you want to keep a log of this?", 80, 300, 209, 17)
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($Log), "wstr", 0, "wstr", 0)
GUICtrlSetColor(-1, 0xff8040)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
GUIStartGroup()
GUICtrlSetTip(-1, "Back up PST files, Favorites, Desktop, Documents, and Outlook contacts")
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$strPrompt = "Windows User Profile back up and restore" & @CRLF
$strPrompt &= "" & @CRLF
$strPrompt &= "1) Select the Destination for the Backup User Profile." & @CRLF
$strPrompt &= "" & @CRLF
$strPrompt &= "2) Select User to backup." & @CRLF & "*Leave blank for current login user" & @CRLF
$strPrompt &= "" & @CRLF
$strPrompt &= "3) Press OK." & @CRLF
$strPrompt &= "" & @CRLF
$strPrompt &= "It is compatible with Windows XP/Vista/Windows 7/ Windows 8/ Windows 8.1/ Server 2003/Server 2008."
$strPrompt &= @CRLF & "As the script is written, it will back up and restore All the Standard folder in User Profile." & @CRLF
$strPrompt &= "plus any ""*.pst"" files and Outlook contacts stored in the user's profile." & @CRLF
$strPrompt &= @CRLF & "When selecting the location to restore from please select the folder that the back up folder is saved to, and not the folder with the user's name."
$strPrompt &= @CRLF & @CRLF & "Example: Back ups are saved to the ""E:"" drive in the folder called ""Backups"", and the user's name is ""Jim"" (E:\Backups\Jim)"
$strPrompt &= @CRLF & "Select the folder ""E:\Backups"" and not the ""E:\Backups\Jim"" folder."
While 1
    Sleep(100)
WEnd
#Region BUR Functions
#cs
    ;===========================================================================

    Checks the chosen path to see if it exists, and if it can be
    written to if backing up, or it checks to see that the
    restore folder is where you said it was.

    ;===========================================================================
#ce
Func _CheckValidPaths()
    Local $TestFile, $Test
    If $Restore = 1 Then
        If Not FileExists($strLocation) Then
            GUISetState(@SW_HIDE)
            _MsgBox($MB_ICONexclam, "&OK", "Restore - Bad Path", "The path you selected " & "'" & $strLocation & "'" & " doesn't contain any back ups for the selected user, please try again", $Timeout, $Pos, $Vpos)
            GUISetState(@SW_SHOW)
            Return -1
        EndIf
    Else
        $TestFile = $SavePath & "\testfile"
        $Test = FileOpen($TestFile, 8)
        FileClose($Test)
        If Not FileExists($SavePath) Then
            GUISetState(@SW_HIDE)
            _MsgBox($MB_ICONexclam, "&OK", "Backup - Bad Path", "The path you selected " & "'" & $SavePath & "'" & " is an invalid path, please try again", $Timeout, $Pos, $Vpos)
            GUISetState(@SW_SHOW, $Form1)
            Return -1
        EndIf
        FileDelete($TestFile)
    EndIf
EndFunc   ;==>_CheckValidPaths
#cs
    ;===========================================================================

    _CopyFiles

    ;===========================================================================
#ce
;~ Func _CopyFiles(ByRef $strSearch, ByRef $ArrayItem)
;~     Local $strRunXcopy
;~     $strRunXcopy = " Robocopy.exe """ & $strSearch & """ """ & $SavePath _
;~              & $CopyPath[$ArrayItem] & """ /s /copyall /256 /xd"
;~     If $LogFlag = 1 Then
;~         $strRunXcopy &= " >>" & Chr(34) & $LogPath & $LogType & Chr(34) & " 2>&1"
;~     EndIf
;~     RunWait(@ComSpec & " /c title " & $CopyPath[$ArrayItem] & "|" & $strRunXcopy, "", @SW_HIDE)
;~ EndFunc   ;==>_CopyFiles


Func _CopyFiles(ByRef $strSearch, ByRef $ArrayItem)
    Local $strRunXcopy
    $strRunXcopy = " xcopy.exe """ & $strSearch & """ """ & $SavePath _
             & $CopyPath[$ArrayItem] & """ /y /s /h /i /c /k"
    If $LogFlag = 1 Then
        $strRunXcopy &= " >>" & Chr(34) & $LogPath & $LogType & Chr(34) & " 2>&1"
    EndIf
    RunWait(@ComSpec & " /c title " & $CopyPath[$ArrayItem] & "|" & $strRunXcopy, "", @SW_HIDE)
EndFunc   ;==>_CopyFiles

#cs
    ;===========================================================================




    ;===========================================================================
#ce
Func _LogFile()
    $LogFile = FileOpen($LogPath & $LogType, 2)
    FileClose($LogFile)
EndFunc   ;==>_LogFile
#cs
    ;===========================================================================

    Initiates the browse for folder function and returns the path selected by
    user.

    ;===========================================================================
#ce
Func BrowseButtonclick()
    $strSavePath = FileSelectFolder("Select a drive letter or folder, don't select My Computer", _
            "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 7)
    GUICtrlSetData($Input1, $strSavePath)
EndFunc   ;==>BrowseButtonclick
#cs
    ;===========================================================================

    Cancel button exits the script

    ;===========================================================================
#ce
Func CancelButton1Click()
    Exit
EndFunc   ;==>CancelButton1Click
#cs
    ;===========================================================================

    Calls the Help message box

    ;===========================================================================
#ce
Func HelpButton1Click()
    GUISetState(@SW_HIDE)
    $Icon = $MB_ICONINFO
    $Button = "&OK"
    $Title = "Instructions"
    $Text = $strPrompt
    Opt("MustDeclareVars", 0)
    _MsgBox($Icon, $Button, $Title, $Text, $Timeout, $Pos, $Vpos)
    GUISetState(@SW_SHOW, $Form1)
    Opt("MustDeclareVars", 1)
EndFunc   ;==>HelpButton1Click
#cs
    ;===========================================================================




    ;===========================================================================
#ce
;
;
Func OKButton1Click()
    Local $Test, $SavedTo
    ;   You pressed the OK button, now we are going to read your settings
    $Backup = GUICtrlRead($Radio2)
    $Restore = GUICtrlRead($Radio1)
    $SavePath = GUICtrlRead($Input1)
    $LogFlag = GUICtrlRead($Log)
    $UserName1 = GUICtrlRead($UserName)
    If $UserName1 <> "0" Then
        Local $Split[3], $OK
        $OK = False
        $Split = StringSplit($sUserList, "|")
        For $I In $Split
            If $UserName1 = $I Then $OK = True
        Next
                If Not $OK Then
            $UserName1 = @UserName
        EndIf
    Else
        Return
    EndIf
    Select
        Case StringLen($UserName1) = 0
            $Icon = $MB_ICONexclam
            $Button = "OK"
            $Title = "No user name selected"
            $Text = "You need to select the user before starting the process. Please try again"
            $Pos = $Form1
            _MsgBox($Icon, $Button, $Title, $Text, $Timeout, $Pos, $Vpos)
            Return
        Case $SavePath = "" ; No path selected
            GUISetState(@SW_HIDE)
            $Icon = $MB_ICONINFO
            $Button = "&OK"
            $Title = "No drive selected"
            $Text = "You need to put in the save/restore path"
            _MsgBox($Icon, $Button, $Title, $Text, $Timeout, $Pos, $Vpos)
            GUICtrlSetData($UserName1, $sUserList)
            GUISetState(@SW_SHOW)
            Return
        Case StringLeft($SavePath, 1) = "C"
            $Icon = $MB_ICONexclam
            $Button = "OK"
            $Title = "Don't use C: drive"
            $Text = "You can't back up the files to the same drive you're copying from, ple" & _
                    "ase don't select the C: drive. Please try again"
            $Pos = $Form1
            _MsgBox($Icon, $Button, $Title, $Text, $Timeout, $Pos, $Vpos)
            Return
        Case StringLen($SavePath) = 1 ; Just drive letter entered?
            $SavePath &= ":\"
        Case StringRight($SavePath, 1) <> "\"
            $SavePath &= "\"
    EndSelect
    $SavePath &= $UserName1
    ;===========================================================================
    ;   Now that we know where you're saving the data to, we need to set some
    ;   variables to tell it what folders/files to back up
    ;===========================================================================
    If $Backup = 1 Then
        If $NewOS Then
            $strLocation = "C:\Users\" & $UserName1
            DirCreate($SavePath)
            $LogPath = $SavePath
            $LogType = "\Backup.log"
        Else
            $strLocation = "C:\Documents and Settings\" & $UserName1
            DirCreate($SavePath)
            $LogPath = $SavePath
            $LogType = "\Backup.log"
        EndIf
    Else
        If $NewOS Then
            $strLocation = $SavePath
            $SavePath = "C:\Users\" & $UserName1
            $LogPath = $strLocation
            $LogType = "\Restore.log"
        Else
            $strLocation = $SavePath
            $SavePath = "C:\Documents and Settings\" & $UserName1
            $LogPath = $strLocation
            $LogType = "\Restore.log"
        EndIf
    EndIf
    If Not $NewOS Then
        $CopyPath[0] = "\Application Data\SecureAge Technology\SecureAge\profiles"
        $CopyPath[1] = "\Application Data\Microsoft\Outlook"
        $CopyPath[2] = "\Application Data\Microsoft\Signatures"
        $CopyPath[3] = "\Application Data\Microsoft\Stationery"
        $CopyPath[4] = "\Application Data\Microsoft\Templates"
        $CopyPath[5] = "\*.pst"
        $CopyPath[6] = "\My Documents"
        $CopyPath[7] = "\Desktop"
        $CopyPath[8] = "\Contacts"
        $CopyPath[9] = "\Downloads"
        $CopyPath[10] = "\Favorites"
        $CopyPath[11] = "\Links"
        $CopyPath[12] = "\My Music"
        $CopyPath[13] = "\My Pictures"
        $CopyPath[14] = "\My Videos"

    Else
        $CopyPath[0] = "\AppData\Roaming\SecureAge Technology\SecureAge\profiles"
        $CopyPath[1] = "\AppData\Roaming\Microsoft\Outlook"
        $CopyPath[2] = "\AppData\Roaming\Microsoft\Signatures"
        $CopyPath[3] = "\AppData\Roaming\Microsoft\Stationery"
        $CopyPath[4] = "\AppData\Roaming\Microsoft\Templates"
        $CopyPath[5] = "\*.pst"
        $CopyPath[6] = "\Documents"
        $CopyPath[7] = "\Desktop"
        $CopyPath[8] = "\Contacts"
        $CopyPath[9] = "\Downloads"
        $CopyPath[10] = "\Favorites"
        $CopyPath[11] = "\Links"
        $CopyPath[12] = "\My Music"
        $CopyPath[13] = "\My Pictures"
        $CopyPath[14] = "\My Videos"

    EndIf
    $Loop = 14
;~     If $Redirect = 1 Then $Loop = 2
    GUISetState(@SW_HIDE)
    $Form2 = GUICreate("Copying!", 300, ($Loop + 1) * 33)
    GUISetBkColor(0x0008000, $Form2)
    GUISetState()
    For $I = 0 To $Loop
        GUICtrlCreateLabel(StringMid($CopyPath[$I], 2), 50, 20 + $I * 30, 230, 20)
        GUICtrlSetFont(-1, Default, 800, Default)
        GUICtrlSetColor(-1, 0x0FFFFFF)
    Next
    $Test = _CheckValidPaths()
    If $Test = -1 Then Return
    If $LogFlag = $GUI_CHECKED Then _LogFile()
    For $ArrayItem = 0 To $Loop
        $Search = $strLocation & $CopyPath[$ArrayItem]
        _CopyFiles($Search, $ArrayItem)
        $Search = ""
        GUICtrlCreateLabel(Chr(214), 25, 20 + $ArrayItem * 30, 10, 10)
        GUICtrlSetFont(-1, Default, 800, Default, "Symbol")
        GUICtrlSetColor(-1, 0x0FFFFFF)
        GUICtrlCreateLabel(StringMid($CopyPath[$ArrayItem], 2), 50, 20 + $ArrayItem * 30, 230, 20)
        GUICtrlSetFont(-1, Default, 800, 8)
        GUICtrlSetColor(-1, 0x0FFFFFF)
    Next
    Sleep(2000)
    GUISetState(@SW_HIDE)
    If $Backup = 1 Then
        $SavedTo = "Your files were saved to " & $LogPath
    Else
        $SavedTo = "You have restored the files for " & $UserName1
    EndIf
    _MsgBox($MB_ICONexclam, "&OK", "Done!", "We're done!" & @CRLF & @CRLF & $SavedTo, $Timeout, $Form2, $Vpos)
    GUISetState(@SW_SHOW, $Form1)

EndFunc   ;==>OKButton1Click
#EndRegion BUR Functions
#cs
    ;===========================================================================

    This calls the Extended Message Box functions written by
    Melba23 and added as an #include

    ;===========================================================================
#ce
Func _MsgBox($Icon, $Button, $Title, $Text, $iTimeout = 0, $hWin = "", $iVPos = 0)
    _ExtMsgBoxSet(1, 0, 0x02616FF, 0x02AFF6A, 10, "Consolas")
    _ExtMsgBox($Icon, $Button, $Title, $Text, $iTimeout, $hWin, $iVPos)
EndFunc   ;==>_MsgBox
Func Form1Close()
    Exit
EndFunc   ;==>Form1Close
Link to comment
Share on other sites

  • 1 year later...

Great Job! Probably the single most useful script I've found since stumbling across AutoIT! 

I have one small question/request is it very difficult to add a progress bar with percentage complete to the copy/restore box? 

Thanks! 

DCT

copy_screenshot.jpg

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...