Jump to content

GUICreate Select Radio Button


Recommended Posts

Again I'm trying to come up with a script for work and although I have the basics, I want to try to make it a little more comlplex and I'm looking for some assitance

Basically I have this (not full script)

GUICreate ( 'Title' )
$Radio1 = GUICreateRadio ( 'Radio1', 25, 20, 100 )
$Radio2 = GUICreateRadio ( 'Radio2', 125, 20, 100 )

Now if $Radio1 is selected

If GUICtrlRead ( $Radio1 ) = $GUI_Checked Then
   GUICtrlCreateLable ( 'New Option', 25, 65, 280, 20 )
   $Combo1 = GUICtrlCreateCombo ( '', 25, 75, 280, 20 )

The problem I have is when I select the radio button and the new option populates it is flickering, like it keeps refreshing.

I have no idea on how I can make a GUICreate window which when the radio button is selected a new option appears.

The reason I'm creating the script is to backup and restore files. If backing up, I give options on what to back up, if restoring I would rather not have the option to select files

Hope I explained this well enough

Link to comment
Share on other sites

One way

#include <GUIConstantsEx.au3>

GUICreate('Title')
$Radio1 = GUICtrlCreateRadio('Radio1', 25, 20, 100)
$Radio2 = GUICtrlCreateRadio('Radio2', 125, 20, 100)
$Label1 = GUICtrlCreateLabel('New Option', 25, 65, 280, 20)
GUICtrlSetState($Label1, $GUI_HIDE) ;although not necessary in this example, we will hide the $Label1 at startup
$Combo1 = GUICtrlCreateCombo('Combo', 25, 75, 280, 20)
GUICtrlSetState($Combo1, $GUI_HIDE) ;although not necessary in this example, we will hide the $Combo1 at startup

GUISetState()

While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then ExitLoop

    Switch GUICtrlRead($Radio1)
        Case $GUI_Checked   ;Radio1 checked
            If BitAND(GUICtrlGetState($Label1), $GUI_HIDE) Then GUICtrlSetState($Label1, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($Combo1), $GUI_HIDE) Then GUICtrlSetState($Combo1, $GUI_SHOW) ;if hidden, then show
        Case Else   ;Radio1 not checked
            If BitAND(GUICtrlGetState($Label1), $GUI_SHOW) Then GUICtrlSetState($Label1, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($Combo1), $GUI_SHOW) Then GUICtrlSetState($Combo1, $GUI_HIDE) ;if visible, then hide
    EndSwitch
WEnd

MsgBox(0, 'State at Exit', '$Label1 = ' & GUICtrlGetState($Label1) & @LF & '$Combo1 = ' & GUICtrlGetState($Combo1))

Edit: Made a cosmetic change, added comments

Edited by Varian
Link to comment
Share on other sites

Once again, thank you for your help, I believe you've helped me at least once here...

So with what you gave me I was able to tweak it some to almost get the result I was looking for, if you could just help me push through to the end...

here is what I have so far

#include <GUIConstantsEx.au3>
#include <File.au3>
#include <WindowsConstants.au3>

Opt ( 'MustDeclareVars', 1 )

Global $FileToPopulate, $UserList, $BackUp, $Restore, $Files, $LocalFile, $Favorites, $OutlookCf, $DesktopCf, $Okay, $Msg

    If @OSVersion = 'WIN_7' Then RunWait ( 'cmd /c dir /b "C:\Users" > ' & @TempDir & '\UserList', '', @SW_HIDE )
    If @OSVersion = 'WIN_XP' Then RunWait ( 'cmd /c dir /b "C:\Documents and Settings" > ' & @TempDir & '\UserList', '', @SW_HIDE )
    $FileToPopulate = @TempDir & '\UserList'

GUICreate('BackUp/Restore User Information')
    ; Select User
        GUICtrlCreateLabel ( 'Select User to Backup', 25, 20, 280, 20 )
        $UserList = GUICtrlCreateCombo ( '', 25, 35, 175, 20 )
            Local $aFileArray
            _FileReadToArray($FileToPopulate, $aFileArray)
            _PopulateCombo($UserList, $aFileArray)
    ; Backup or Restore option
        $Backup = GUICtrlCreateRadio('Backup', 25, 75, 100)
        $Restore = GUICtrlCreateRadio('Restore', 150, 75, 100)
    ; Auto populated if Backup is selected, hidden if not
        $Files = GUICtrlCreateLabel ( 'Select Files To BackUp', 25, 100, 120, 20 )
            GUICtrlSetState ( $Files, $GUI_HIDE )
        $LocalFile = GUICtrlCreateCheckbox ( 'Local Storage', 25, 115, 85, 20 )
            GUICtrlSetState ( $LocalFile, $GUI_HIDE )
        $Favorites = GUICtrlCreateCheckbox ( 'Favorites', 150, 115, 80, 20 )
            GUICtrlSetState ( $Favorites, $GUI_HIDE )
        $OutlookCf = GUICtrlCreateCheckbox ( 'Outlook', 25, 135, 80, 20 )
            GUICtrlSetState ( $OutlookCf, $GUI_HIDE )
        $DesktopCf = GUICtrlCreateCheckbox ( 'Desktop', 150, 135, 80, 20 )
            GUICtrlSetState ( $DesktopCf, $GUI_HIDE )
        $Okay = GUICtrlCreateButton ( 'Okay', 25, 150, 30, 20 )
GUISetState()

While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then ExitLoop

    Switch GUICtrlRead($Backup)
    Case $GUI_Checked   ;Backup checked
            If BitAnd(GUICtrlGetState($Files), $GUI_HIDE) Then GUICtrlSetState($Files, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($LocalFile), $GUI_HIDE) Then GUICtrlSetState($LocalFile, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($Favorites), $GUI_HIDE) Then GUICtrlSetState($Favorites, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($OutlookCf), $GUI_HIDE) Then GUICtrlSetState($OutlookCf, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($DesktopCf), $GUI_HIDE) Then GUICtrlSetState($DesktopCf, $GUI_SHOW) ;if hidden, then show
            Case Else   ;Backup not checked
            If BitAnd(GUICtrlGetState($Files), $GUI_SHOW) Then GUICtrlSetState($Files, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($LocalFile), $GUI_SHOW) Then GUICtrlSetState($LocalFile, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($Favorites), $GUI_SHOW) Then GUICtrlSetState($Favorites, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($OutlookCf), $GUI_SHOW) Then GUICtrlSetState($OutlookCf, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($DesktopCf), $GUI_SHOW) Then GUICtrlSetState($DesktopCF, $GUI_HIDE) ;if visible, then hide
    EndSwitch   
WEnd        
        If $Msg = $Okay Then
            If GUICtrlRead ( $LocalFile ) = $GUI_CHECKED Then
                Msgbox ( 0, '', 'Local Storage' ) ;Will replace with copy
            If GUICtrlRead ( $Favorites ) = $GUI_CHECKED Then
                MsgBox ( 0, '', 'Favorites' ) ; Will replace with copy
            If GUICtrlRead ( $OutlookCf ) = $GUI_CHECKED Then
                MsgBox ( 0, '', 'OutlookCf' ) ;will replace with copy
            If GUICtrlRead ( $DesktopCf ) = $GUI_CHECKED Then
                MsgBox ( 0, '', 'Desktop' ) ;will replace with copy
            EndIf
        EndIf
    EndIf
EndIf
EndIf

Func _PopulateCombo($hwndCTRLID, $vInfo)
    Local $sStoreForCombo = ''
    For $iCount = 1 To UBound($vInfo) - 1
        If $vInfo[$iCount] <> '' Then $sStoreForCombo &= $vInfo[$iCount] & '|'
    Next
    GUICtrlSetData($hwndCTRLID, $sStoreForCombo)
EndFunc

What I need help on is this

When I click the OK button, nothing happens, I'm sure this is a simple fix... for now I just have message boxes popping up because I already know how to use the COPY I'm going to put in the msgbox place

Also, how do you close the window after clicking okay and perhaps giving some sort of progress...

I've tried to make it so that the backup can be used on Windows XP and/or Windows 7 and I'm sure there is cleaning up to do with my scripting!

Thanks again for your help (in advance this time too!)

Edited by Elephant007
Link to comment
Share on other sites

Your $OKAY was not in the While...WEnd loop so you never polled it being clicked. The structure of your If..Then statement was such that if "Local Storage" was not selected the entire condition failed and would not display a message box. I also put the selections into an array so you can create one backup function and loop through the selections that are checked.

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <File.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $FileToPopulate, $UserList, $BackUp, $Restore, $Files, $LocalFile, $Favorites, $OutlookCf, $DesktopCf, $Okay, $Msg

If @OSVersion = 'WIN_7' Then RunWait('cmd /c dir /b "C:\Users" > ' & @TempDir & '\UserList', '', @SW_HIDE)
If @OSVersion = 'WIN_XP' Then RunWait('cmd /c dir /b "C:\Documents and Settings" > ' & @TempDir & '\UserList', '', @SW_HIDE)
$FileToPopulate = @TempDir & '\UserList'

GUICreate('BackUp/Restore User Information')
; Select User
GUICtrlCreateLabel('Select User to Backup', 25, 20, 280, 20)
$UserList = GUICtrlCreateCombo('', 25, 35, 175, 20)
Local $aFileArray
_FileReadToArray($FileToPopulate, $aFileArray)
_PopulateCombo($UserList, $aFileArray)
; Backup or Restore option
$BackUp = GUICtrlCreateRadio('Backup', 25, 75, 100)
$Restore = GUICtrlCreateRadio('Restore', 150, 75, 100)
; Auto populated if Backup is selected, hidden if not
$Files = GUICtrlCreateLabel('Select Files To BackUp', 25, 100, 120, 20)
GUICtrlSetState($Files, $GUI_HIDE)
$LocalFile = GUICtrlCreateCheckbox('Local Storage', 25, 115, 85, 20)
GUICtrlSetState($LocalFile, $GUI_HIDE)
$Favorites = GUICtrlCreateCheckbox('Favorites', 150, 115, 80, 20)
GUICtrlSetState($Favorites, $GUI_HIDE)
$OutlookCf = GUICtrlCreateCheckbox('Outlook', 25, 135, 80, 20)
GUICtrlSetState($OutlookCf, $GUI_HIDE)
$DesktopCf = GUICtrlCreateCheckbox('Desktop', 150, 135, 80, 20)
GUICtrlSetState($DesktopCf, $GUI_HIDE)
$Okay = GUICtrlCreateButton('Okay', 25, 150, 30, 20)
GUISetState()

While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $Msg = $Okay Then
        Local $Selection[1] = [0]
        If GUICtrlRead($LocalFile) = $GUI_Checked Then _ArrayAdd($Selection, 'Local Storage')
        If GUICtrlRead($Favorites) = $GUI_Checked Then _ArrayAdd($Selection, 'Favorites')
        If GUICtrlRead($OutlookCf) = $GUI_Checked Then _ArrayAdd($Selection, 'OutlookCf')
        If GUICtrlRead($DesktopCf) = $GUI_Checked Then _ArrayAdd($Selection, 'Desktop')
        $Selection[0] = UBound($Selection) - 1
        If $Selection[0] > 0 Then _ArrayDisplay($Selection, 'Your Selections') ;Moved results to Array so you can create a copy function and loop through all selections
        GUISetState(@SW_HIDE)   ;Hide The Main Script
        Local $mText = 'At this point, you will be running your backup function and the GUI will be hidden' & @LF
        $mText &= 'Pressing "OK" simulates the end of the backup and the GUI will be restored'
        MsgBox(262208, 'Notes', $mText)
        GUISetState()
    EndIf
    Switch GUICtrlRead($BackUp)
        Case $GUI_Checked ;Backup checked
            If BitAND(GUICtrlGetState($Files), $GUI_HIDE) Then GUICtrlSetState($Files, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($LocalFile), $GUI_HIDE) Then GUICtrlSetState($LocalFile, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($Favorites), $GUI_HIDE) Then GUICtrlSetState($Favorites, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($OutlookCf), $GUI_HIDE) Then GUICtrlSetState($OutlookCf, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($DesktopCf), $GUI_HIDE) Then GUICtrlSetState($DesktopCf, $GUI_SHOW) ;if hidden, then show
        Case Else ;Backup not checked
            If BitAND(GUICtrlGetState($Files), $GUI_SHOW) Then GUICtrlSetState($Files, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($LocalFile), $GUI_SHOW) Then GUICtrlSetState($LocalFile, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($Favorites), $GUI_SHOW) Then GUICtrlSetState($Favorites, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($OutlookCf), $GUI_SHOW) Then GUICtrlSetState($OutlookCf, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($DesktopCf), $GUI_SHOW) Then GUICtrlSetState($DesktopCf, $GUI_HIDE) ;if visible, then hide
    EndSwitch
WEnd


Func _PopulateCombo($HwndCTRLID, $vInfo)
    Local $sStoreForCombo = ''
    For $iCount = 1 To UBound($vInfo) - 1
        If $vInfo[$iCount] <> '' Then $sStoreForCombo &= $vInfo[$iCount] & '|'
    Next
    GUICtrlSetData($HwndCTRLID, $sStoreForCombo)
EndFunc   ;==>_PopulateCombo

EDIT: Edited the script to give you an idea for hiding your GUI while the backup is running, and restoring it when it has finished.

Edited by Varian
Link to comment
Share on other sites

A question if i may, well 2 in fact

1: with the combo menu is it possible to have an "All" so that all profiles if there is multiple ones they can be backed up together?

and

2: In this bit

If GUICtrlRead($LocalFile) = $GUI_Checked Then _ArrayAdd($Selection, 'Local Storage')
        If GUICtrlRead($Favorites) = $GUI_Checked Then _ArrayAdd($Selection, 'Favorites')
        If GUICtrlRead($OutlookCf) = $GUI_Checked Then _ArrayAdd($Selection, 'OutlookCf')
        If GUICtrlRead($DesktopCf) = $GUI_Checked Then _ArrayAdd($Selection, 'Desktop')
        $Selection[0] = UBound($Selection) - 1
        If $Selection[0] > 0 Then _ArrayDisplay($Selection, 'Your Selections') ;Moved results to Array so you can create a copy function and loop through all selections

each section that has been added i assume is added to the $Selection ?? is that right so how would i access that if i were doing a robocopy backup for eg like this

$RunOutcome = Runwait(@ComSpec & " /k " & "RoboCopy " & $sSource & " " & $sDest & " /XJD /XJF /R:0 /W:0 /NJS /XF " & $_exc_vista_files " /XD " & $sDest & $FileMask & " &&pause", "", @SW_show)

Can the array be accessed by replacing

$sSource
with
$Selection
?
Link to comment
Share on other sites

This script is turning out to be really nice, one feature I would like to add to is (and I have no idea how) show the size of the directories that I would like to backup

here's a copy of a more fuctioning script (for Windows XP)

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <File.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $FileToPopulate, $UserList, $BackUp, $Restore, $Files, $LocalFile, $Favorites, $OutlookCf, $DesktopCf, $Okay, $Msg, $UserName, $GetFileSizes, $Size

If @OSVersion = 'WIN_7' Then RunWait('cmd /c dir /b "C:\Users" > ' & @TempDir & '\UserList', '', @SW_HIDE)
If @OSVersion = 'WIN_XP' Then RunWait('cmd /c dir /b "C:\Documents and Settings" > ' & @TempDir & '\UserList', '', @SW_HIDE)
$FileToPopulate = @TempDir & '\UserList'

GUICreate('BackUp/Restore User Information')
; Select User
GUICtrlCreateLabel('Select User to Backup', 25, 20, 280, 20)
$UserList = GUICtrlCreateCombo('', 25, 35, 175, 20)
Local $aFileArray
_FileReadToArray($FileToPopulate, $aFileArray)
_PopulateCombo($UserList, $aFileArray)
; Backup or Restore option
$BackUp = GUICtrlCreateRadio('Backup', 25, 75, 100)
$Restore = GUICtrlCreateRadio('Restore', 150, 75, 100)
; Auto populated if Backup is selected, hidden if not
$Files = GUICtrlCreateLabel('Select Files To BackUp', 25, 100, 120, 20)
GUICtrlSetState($Files, $GUI_HIDE)
$LocalFile = GUICtrlCreateCheckbox('Local Storage', 25, 115, 85, 20)
GUICtrlSetState($LocalFile, $GUI_HIDE)
$Favorites = GUICtrlCreateCheckbox('Favorites', 150, 115, 80, 20)
GUICtrlSetState($Favorites, $GUI_HIDE)
$OutlookCf = GUICtrlCreateCheckbox('Outlook', 25, 135, 80, 20)
GUICtrlSetState($OutlookCf, $GUI_HIDE)
$DesktopCf = GUICtrlCreateCheckbox('Desktop', 150, 135, 80, 20)
GUICtrlSetState($DesktopCf, $GUI_HIDE)
$Okay = GUICtrlCreateButton('Okay', 25, 150, 30, 20)
$GetFileSizes = GUICtrlCreateButton ( 'Get File Size(s)', 75, 150, 30, 20 )
GUISetState()

While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then ExitLoop
       $UserName = GUICtrlRead ( $UserList )
    If $Msg = $Okay Then
        Local $Selection[1] = [0]
        If GUICtrlRead($LocalFile) = $GUI_Checked Then _ArrayAdd($Selection, 'Local Storage')
        If GUICtrlRead($Favorites) = $GUI_Checked Then _ArrayAdd($Selection, 'Favorites')
        If GUICtrlRead($OutlookCf) = $GUI_Checked Then _ArrayAdd($Selection, 'OutlookCf')
        If GUICtrlRead($DesktopCf) = $GUI_Checked Then _ArrayAdd($Selection, 'Desktop')
        $Selection[0] = UBound($Selection) - 1
        GUISetState(@SW_HIDE)   ;Hide The Main Script
                MsgBox ( 0, '', $UserName )
                    If GUICtrlRead ( $LocalFile ) = $GUI_Checked Then RunWait ( 'xcopy /e /h /y /i "C:\Local Storage\' & $UserName '\*"' & ' "\\Server\Transfer\UserProfileBackup\' & $UserName & '\LocalStorage\*"', '', @SW_HIDE )
                    If GUICtrlRead ( $Favorites ) = $GUI_Checked Then RunWait ( 'xcopy /e /h /y /i "C:\Documents and Settings\' & $UserName & '\Favorites\*"' & ' "\\Server\Transfer\UserProfileBackup\' & $UserName & '\Favorites\*"', '', @SW_HIDE )
                    If GUICtrlRead ( $DesktopCf ) = $GUI_Checked Then RunWait ( 'xcopy /e /h /y /i "C:\Documents and Settings\' & $UserName & '\Desktop\*"' & ' "\\Server\Transfer\UserProfileBackup\' & $UserName & '\Desktop\*"', '', @SW_HIDE )
                    If GUICtrlRead ( $OutlookCf ) = $GUI_Checked Then
                        RunWait ( 'xcopy /e /h /y /i "C:\Documents and Settings\' & $UserName & '\Application Data\Microsoft\Outlook\*"' & ' "\\Server\Transfer\UserProfileBackup\' & $UserName & '\Outlook\Outlook1\*"', '', @SW_HIDE )
                        RunWait ( 'xcopy /e /h /y /i "C:\Documents and Settings\' & $UserName & '\Local Settings\Application Data\Microsoft\Outlook\*"' & ' "\\Server\Transfer\UserProfileBackup\' & $UserName & '\Outlook\Outlook2\*"', '', @SW_HIDE )
                        RunWait ( 'xcopy /e /h /y /i "C:\Documents and Settings\' & $UserName & '\Local Settings\Application Data\Microsoft\Signatures\*"' & ' "\\Server\Transfer\UserProfileBackup\' & $UserName & '\Outlook\Sigunatures\*"', '', @SW_HIDE )
                        RunWait ( 'reg export "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook" "\\Server\Transfer\UserProfileBackup\' & $UserName & '\Outlook\Profile.reg"', '', @SW_HIDE )
                    EndIf
        GUISetState()
    EndIf
    Switch GUICtrlRead($BackUp)
        Case $GUI_Checked ;Backup checked
            If BitAND(GUICtrlGetState($Files), $GUI_HIDE) Then GUICtrlSetState($Files, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($LocalFile), $GUI_HIDE) Then GUICtrlSetState($LocalFile, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($Favorites), $GUI_HIDE) Then GUICtrlSetState($Favorites, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($OutlookCf), $GUI_HIDE) Then GUICtrlSetState($OutlookCf, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($DesktopCf), $GUI_HIDE) Then GUICtrlSetState($DesktopCf, $GUI_SHOW) ;if hidden, then show
        Case Else ;Backup not checked
            If BitAND(GUICtrlGetState($Files), $GUI_SHOW) Then GUICtrlSetState($Files, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($LocalFile), $GUI_SHOW) Then GUICtrlSetState($LocalFile, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($Favorites), $GUI_SHOW) Then GUICtrlSetState($Favorites, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($OutlookCf), $GUI_SHOW) Then GUICtrlSetState($OutlookCf, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($DesktopCf), $GUI_SHOW) Then GUICtrlSetState($DesktopCf, $GUI_HIDE) ;if visible, then hide
    EndSwitch
WEnd


Func _PopulateCombo($HwndCTRLID, $vInfo)
    Local $sStoreForCombo = ''
    For $iCount = 1 To UBound($vInfo) - 1
        If $vInfo[$iCount] <> '' Then $sStoreForCombo &= $vInfo[$iCount] & '|'
    Next
    GUICtrlSetData($HwndCTRLID, $sStoreForCombo)
EndFunc   ;==>_PopulateCombo

I added this line so you can run it on Windows7 and populate a list of users

If @OSVersion = 'WIN_7' Then RunWait('cmd /c dir /b "C:\Users" > ' & @TempDir & '\UserList', '', @SW_HIDE)
Link to comment
Share on other sites

I am not sure what directory you intended with "Local Storage", so I pointed it to the Documents folder. Test this with 7/XP.

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <File.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $FileToPopulate, $UserList, $BackUp, $Restore, $Files, $LocalFile, $Favorites, $OutlookCf, $DesktopCf, $Okay, $Msg, $AllUsersSelect

Switch @OSVersion
    Case 'WIN_7'
        RunWait('cmd /c dir /b "C:\Users" > ' & @TempDir & '\UserList', '', @SW_HIDE)
    Case 'WIN_XP'
        RunWait('cmd /c dir /b "C:\Documents and Settings" > ' & @TempDir & '\UserList', '', @SW_HIDE)
EndSwitch
$FileToPopulate = @TempDir & '\UserList'

GUICreate('BackUp/Restore User Information')
; Select User
GUICtrlCreateLabel('Select User to Backup', 25, 20, 280, 20)
$UserList = GUICtrlCreateCombo('', 25, 35, 175, 20)
$AllUsersSelect = GUICtrlCreateCheckbox('Select All Profiles', 210, 35, 105, 20)
Local $aFileArray
_FileReadToArray($FileToPopulate, $aFileArray)
_PopulateCombo($UserList, $aFileArray)
; Backup or Restore option
$BackUp = GUICtrlCreateRadio('Backup', 25, 75, 100)
GUICtrlSetState($Okay, $GUI_UNCHECKED)
$Restore = GUICtrlCreateRadio('Restore', 150, 75, 100)
GUICtrlSetState($Okay, $GUI_UNCHECKED)
; Auto populated if Backup is selected, hidden if not
$Files = GUICtrlCreateLabel('Select Files To BackUp', 25, 100, 120, 20)
GUICtrlSetState($Files, $GUI_HIDE)
$LocalFile = GUICtrlCreateCheckbox('Local Storage', 25, 115, 85, 20)
GUICtrlSetState($LocalFile, $GUI_HIDE)
$Favorites = GUICtrlCreateCheckbox('Favorites', 150, 115, 80, 20)
GUICtrlSetState($Favorites, $GUI_HIDE)
$OutlookCf = GUICtrlCreateCheckbox('Outlook', 25, 135, 80, 20)
GUICtrlSetState($OutlookCf, $GUI_HIDE)
$DesktopCf = GUICtrlCreateCheckbox('Desktop', 150, 135, 80, 20)
GUICtrlSetState($DesktopCf, $GUI_HIDE)
$Okay = GUICtrlCreateButton('OK', 25, 160, 30, 20)
GUICtrlSetState($Okay, $GUI_DISABLE)
GUISetState()

While 1
    Local $ProfileList
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then ExitLoop

    #region Enable OK Button    ;enaable OK button only if Profile is selected and one of the radio buttons are selected
    If $Msg = $AllUsersSelect Then
        Switch GUICtrlRead($AllUsersSelect)
            Case $GUI_CHECKED
                GUICtrlSetData($UserList, '')
                GUICtrlSetState($UserList, $GUI_DISABLE)
            Case $GUI_UNCHECKED
                GUICtrlSetData($UserList, '')
                GUICtrlSetState($UserList, $GUI_ENABLE)
        EndSwitch
    EndIf
    If BitAND(GUICtrlGetState($Okay), $GUI_DISABLE) Then
        If BitAND(GUICtrlRead($BackUp), $GUI_CHECKED) Or BitAND(GUICtrlRead($Restore), $GUI_CHECKED) Then
            If StringRegExp(GUICtrlRead($UserList), '^[^\s]+$', 0) Or GUICtrlRead($AllUsersSelect) = $GUI_CHECKED Then
                GUICtrlSetState($Okay, $GUI_ENABLE)
            EndIf
        EndIf
    EndIf
    #endregion Enable OK Button ;enaable OK button only if Profile is selected and one of the radio buttons are selected

    If $Msg = $Okay Then
        Local $Selection[1] = [0]
        If GUICtrlRead($LocalFile) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Local Storage')
        If GUICtrlRead($Favorites) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Favorites')
        If GUICtrlRead($OutlookCf) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Outlook')
        If GUICtrlRead($DesktopCf) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Desktop')
        $Selection[0] = UBound($Selection) - 1
        If $Selection[0] > 0 Then
            GUISetState(@SW_HIDE) ;Hide The Main Script

            If GUICtrlRead($AllUsersSelect) = $GUI_CHECKED Then
                _Backup($aFileArray, $Selection)
            Else
                _Backup(GUICtrlRead($UserList), $Selection)
            EndIf

            GUISetState()
        EndIf
    EndIf
    Switch GUICtrlRead($BackUp)
        Case $GUI_CHECKED ;Backup checked
            If BitAND(GUICtrlGetState($Files), $GUI_HIDE) Then GUICtrlSetState($Files, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($LocalFile), $GUI_HIDE) Then GUICtrlSetState($LocalFile, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($Favorites), $GUI_HIDE) Then GUICtrlSetState($Favorites, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($OutlookCf), $GUI_HIDE) Then GUICtrlSetState($OutlookCf, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($DesktopCf), $GUI_HIDE) Then GUICtrlSetState($DesktopCf, $GUI_SHOW) ;if hidden, then show
        Case Else ;Backup not checked
            If BitAND(GUICtrlGetState($Files), $GUI_SHOW) Then GUICtrlSetState($Files, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($LocalFile), $GUI_SHOW) Then GUICtrlSetState($LocalFile, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($Favorites), $GUI_SHOW) Then GUICtrlSetState($Favorites, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($OutlookCf), $GUI_SHOW) Then GUICtrlSetState($OutlookCf, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($DesktopCf), $GUI_SHOW) Then GUICtrlSetState($DesktopCf, $GUI_HIDE) ;if visible, then hide
    EndSwitch
WEnd


Func _PopulateCombo($HwndCTRLID, $vInfo)
    Local $sStoreForCombo = ''
    For $iCount = 1 To UBound($vInfo) - 1
        If $vInfo[$iCount] <> '' Then $sStoreForCombo &= $vInfo[$iCount] & '|'
    Next
    GUICtrlSetData($HwndCTRLID, $sStoreForCombo)
EndFunc   ;==>_PopulateCombo

Func _Backup($iProfiles, $iFolders)
    Local $CurrentProfile, $CurrentFolder, $Directory, $i, $Destination = 'E:\Backup'
    If Not IsArray($iFolders) Then Return
    If Not IsArray($iProfiles) Then
        Local $nArray[1] = [$iProfiles]
    Else
        Local $nArray = $iProfiles
    EndIf
    For $CurrentProfile In $nArray
        If Not $CurrentProfile Then ContinueLoop
        For $CurrentFolder = 1 To $iFolders
            Switch @OSVersion
                Case 'WIN_7'
                    Local $Folder = 'C:\Users'
                    Switch $CurrentFolder
                        Case 'Local Storage'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Documents'
                        Case 'Favorites'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Favorites'
                        Case 'Outlook'
                            $Directory = $Folder & '\' & $CurrentProfile & '\AppData\Local\Microsoft\Outlook'
                        Case 'Desktop'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Desktop'
                        Case Else
                            ContinueLoop
                    EndSwitch
                Case 'WIN_XP'
                    Local $Folder = 'C:\Documents and Settings'
                    Switch $CurrentFolder
                        Case 'Local Storage'
                            $Directory = $Folder & '\' & $CurrentProfile & '\My Documents'
                        Case 'Favorites'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Favorites'
                        Case 'Outlook'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Local Settings\Application Data\Microsoft\Outlook'
                        Case 'Desktop'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Desktop'
                        Case Else
                            ContinueLoop
                    EndSwitch
            EndSwitch
            _CopyFiles($Directory, $Destination & StringReplace($Directory, $Folder, ''))
        Next
    Next
    Return 1
EndFunc   ;==>_Backup

Func _CopyFiles($Source, $Destination)
    Local $fArray, $TotalSize, $BytesCopied, $hWnd
    $fArray = _FileListToArray_Recursive($Source, '*', 1)
    If Not IsArray($fArray) Then Return

    Local $Size[UBound($fArray)][3]
    $Size[0][0] = $fArray[0]
    For $i = 1 To $fArray[0]
        $Size[$i][0] = $fArray[$i]
        $Size[$i][1] = StringReplace($Size[$i][0], $Source, $Destination)
        $Size[$i][2] = FileGetSize($fArray[$i])
        $TotalSize += $Size[$i][2]
    Next
    $Size[0][2] = $TotalSize

    ProgressOn('Progress Meter', 'Percentage of Total Bytes Completed', '0 percent')
    $hWnd = WinGetHandle('Progress Meter', '')
    WinSetOnTop($hWnd, '', 1)
    For $i = 1 To $Size[0][0]
        If Not $Size[$i][0] Or IsInt($Size[$i][0]) Then ContinueLoop
        WinSetTitle($hWnd, '', StringRegExpReplace($Size[$i][0], '^.+\\', ''))
        FileCopy($Size[$i][0], $Size[$i][1], 9)
        $BytesCopied += $Size[$i][2]
        ProgressSet(Floor(($BytesCopied / $TotalSize) * 100), Floor(($BytesCopied / $TotalSize) * 100) & ' percent')
    Next
    ProgressOff()
EndFunc   ;==>_CopyFiles


Func _FileListToArray_Recursive($sPath, $sFilter = "*", $iRetItemType = 0, $iRetPathType = 2, $bRecursive = True)
    Local $sRet = '', $sRetPath = '', $sOrigPathLen, $sCurrPathLen, $sCurrPath, $Search, $File, $hSearch
    $sPath = StringRegExpReplace($sPath, "[\\/]+\z", "")
    If Not FileExists($sPath) Then Return SetError(1, 1, "")
    If StringRegExp($sFilter, "[\\/ :> <\|]|(?s)\A\s*\z") Then Return SetError(2, 2, "")
    $sPath &= "\|"
    $sOrigPathLen = StringLen($sPath) - 1
    While $sPath
        $sCurrPathLen = StringInStr($sPath, "|") - 1
        $sCurrPath = StringLeft($sPath, $sCurrPathLen)
        $Search = FileFindFirstFile($sCurrPath & $sFilter)
        If @error Then
            $sPath = StringTrimLeft($sPath, $sCurrPathLen + 1)
            ContinueLoop
        EndIf
        Switch $iRetPathType
            Case 1 ; relative path
                $sRetPath = StringTrimLeft($sCurrPath, $sOrigPathLen)
            Case 2 ; full path
                $sRetPath = $sCurrPath
        EndSwitch
        While 1
            $File = FileFindNextFile($Search)
            If @error Then ExitLoop
            If ($iRetItemType + @extended = 2) Then ContinueLoop
            $sRet &= $sRetPath & $File & "|"
        WEnd
        FileClose($Search)
        If $bRecursive Then
            $hSearch = FileFindFirstFile($sCurrPath & "*")
            While 1
                $File = FileFindNextFile($hSearch)
                If @error Then ExitLoop
                If @extended Then $sPath &= $sCurrPath & $File & "\|"
            WEnd
            FileClose($hSearch)
        EndIf
        $sPath = StringTrimLeft($sPath, $sCurrPathLen + 1)
    WEnd
    If Not $sRet Then Return SetError(4, 4, "")
    Return StringSplit(StringTrimRight($sRet, 1), "|")
EndFunc   ;==>_FileListToArray_Recursive
Link to comment
Share on other sites

Local Storage is someone's futile attempt in creating a local directory that users can move their documents to so when their computer is worked on the technician just copies their "Local Storage" to a remote server so when their computer is reimaged their stuff will be saved. I don't like this practice because then users tend to use their Local Storage instead of their My Documents which is redirected to a remote server. I have been pushing to get rid of this directory which is made during the logon script portion of logging into the domain.

I would like to get it so that the user doesn't save anything to their local hard drive... this way techs won't have to back anything up... I'll sure be happy when we migrate to Widnows 7 because Favorites are located in My Documents, then we can redirect their Outlook Signatures and N2K file

One more thing I need to figure out and I think this script will be complete... how in the world do I make it restore these backed up items when the tech selects RESTORE? I know what commands to use to copy the information back and the path the information needs to go to, just how do I activate it with the script..

again thank you for all your help!

EDIT:

Oh man I really like what you have done with adding the "Select All Profiles", super nice!

How can I make the "Select All Profiles" only choose accounts with a DOT in it? Our users naming convention is

FirstName.LastName

Man it's great! You have much skill!

Edited by Elephant007
Link to comment
Share on other sites

In Windows 7:

*Windows 7 keeps the Favorites in the same location as Windows XP..."%USERPROFILE%\Favorites"

*Outlook NK2 files are installed in "%APPDATA%\Microsoft\Outlook"

*Outlook Signatures are stored in "%APPDATA%\Microsoft\Signatures"

*Outlook PSTs are stored in "%LOCALAPPDATA%\Microsoft\Outlook" unless you manually create the file with "Add Data files" feature, in which case they are created in the User's Documents Folder

Select only Profile Names with dots in them

Search for this line

If Not $CurrentProfile Then ContinueLoop
then add this line
If Not StringInStr($CurrentProfile, '.') Then ContinueLoop

As for the Restore, you can hard code the base location...for example, \\SERVER\USERDATA, where you will have Users' folders that have been backed up. Other than that, you can use FileSelectFolder to browse to the user's folder on the network

Check out OutlookTools that is a good utility for a Tech Lab to have as a tool

Link to comment
Share on other sites

I didn't communicate properly, I added the line and it works great for the '.' account... what I was aiming for was having the combo box only populate the '.' accounts

I haven't tested this in the real environment, only at home and it works great...

I did a restore on my home computer and it didn't restore, is this function operational too? I'm trying to dissect the code and can't figure out where the restore process happens

Link to comment
Share on other sites

Here you go

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <File.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $FileToPopulate, $UserList, $BackUp, $Restore, $Files, $LocalFile, $Favorites, $OutlookCf, $DesktopCf, $Okay, $Msg, $AllUsersSelect
Global $BackupDir = 'E:\Backup' ;change this to your backup directory

Switch @OSVersion
    Case 'WIN_7'
        RunWait('cmd /c dir /b "C:\Users" > ' & @TempDir & '\UserList', '', @SW_HIDE)
    Case 'WIN_XP'
        RunWait('cmd /c dir /b "C:\Documents and Settings" > ' & @TempDir & '\UserList', '', @SW_HIDE)
EndSwitch
$FileToPopulate = @TempDir & '\UserList'

GUICreate('BackUp/Restore User Information')
; Select User
GUICtrlCreateLabel('Select User to Backup', 25, 20, 280, 20)
$UserList = GUICtrlCreateCombo('', 25, 35, 175, 20)
$AllUsersSelect = GUICtrlCreateCheckbox('Select All Profiles', 210, 35, 105, 20)
Local $aFileArray
_FileReadToArray($FileToPopulate, $aFileArray)
_PopulateCombo($UserList, $aFileArray)
; Backup or Restore option
$BackUp = GUICtrlCreateRadio('Backup', 25, 75, 100)
GUICtrlSetState($Okay, $GUI_UNCHECKED)
$Restore = GUICtrlCreateRadio('Restore', 150, 75, 100)
GUICtrlSetState($Okay, $GUI_UNCHECKED)
; Auto populated if Backup is selected, hidden if not
$Files = GUICtrlCreateLabel('Select Files To BackUp', 25, 100, 120, 20)
GUICtrlSetState($Files, $GUI_HIDE)
$LocalFile = GUICtrlCreateCheckbox('Local Storage', 25, 115, 85, 20)
GUICtrlSetState($LocalFile, $GUI_HIDE)
$Favorites = GUICtrlCreateCheckbox('Favorites', 150, 115, 80, 20)
GUICtrlSetState($Favorites, $GUI_HIDE)
$OutlookCf = GUICtrlCreateCheckbox('Outlook', 25, 135, 80, 20)
GUICtrlSetState($OutlookCf, $GUI_HIDE)
$DesktopCf = GUICtrlCreateCheckbox('Desktop', 150, 135, 80, 20)
GUICtrlSetState($DesktopCf, $GUI_HIDE)
$Okay = GUICtrlCreateButton('OK', 25, 160, 30, 20)
GUICtrlSetState($Okay, $GUI_DISABLE)
GUISetState()

While 1
    Local $ProfileList
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then ExitLoop

    #region Enable OK Button    ;enaable OK button only if Profile is selected and one of the radio buttons are selected
    If $Msg = $AllUsersSelect Then
        Switch GUICtrlRead($AllUsersSelect)
            Case $GUI_CHECKED
                GUICtrlSetData($UserList, '')
                GUICtrlSetState($UserList, $GUI_DISABLE)
            Case $GUI_UNCHECKED
                GUICtrlSetData($UserList, '')
                GUICtrlSetState($UserList, $GUI_ENABLE)
        EndSwitch
    EndIf
    If BitAND(GUICtrlGetState($Okay), $GUI_DISABLE) Then
        If BitAND(GUICtrlRead($BackUp), $GUI_CHECKED) Or BitAND(GUICtrlRead($Restore), $GUI_CHECKED) Then
            If StringRegExp(GUICtrlRead($UserList), '^[^\s]+$', 0) Or GUICtrlRead($AllUsersSelect) = $GUI_CHECKED Then
                GUICtrlSetState($Okay, $GUI_ENABLE)
            EndIf
        EndIf
    EndIf
    #endregion Enable OK Button ;enaable OK button only if Profile is selected and one of the radio buttons are selected

    #region OK Button pressed
    If $Msg = $Okay Then
        Local $Selection[1] = [0]
        If GUICtrlRead($LocalFile) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Local Storage')
        If GUICtrlRead($Favorites) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Favorites')
        If GUICtrlRead($OutlookCf) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Outlook')
        If GUICtrlRead($DesktopCf) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Desktop')
        $Selection[0] = UBound($Selection) - 1
        If $Selection[0] > 0 Then
            GUISetState(@SW_HIDE) ;Hide The Main GUI
            If GUICtrlRead($BackUp) = $GUI_CHECKED Then Local $sAction = 'Backup'   ;Backup Checked
            If GUICtrlRead($Restore) = $GUI_CHECKED Then    Local $sAction = 'Restore'  ;Restore Checked
            If GUICtrlRead($AllUsersSelect) = $GUI_CHECKED Then
                _StartAction($aFileArray, $Selection, $sAction)
            Else
                If GUICtrlRead($UserList) Then _StartAction(GUICtrlRead($UserList), $Selection, $sAction)
            EndIf
            GUISetState(@SW_SHOW)   ;Restore The Main GUI
        EndIf
    EndIf
    #endregion OK Button pressed

    #region Show/Hide Backup Options
    Switch GUICtrlRead($BackUp)
        Case $GUI_CHECKED ;Backup checked
            If BitAND(GUICtrlGetState($Files), $GUI_HIDE) Then GUICtrlSetState($Files, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($LocalFile), $GUI_HIDE) Then GUICtrlSetState($LocalFile, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($Favorites), $GUI_HIDE) Then GUICtrlSetState($Favorites, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($OutlookCf), $GUI_HIDE) Then GUICtrlSetState($OutlookCf, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($DesktopCf), $GUI_HIDE) Then GUICtrlSetState($DesktopCf, $GUI_SHOW) ;if hidden, then show
        Case Else ;Backup not checked
            If BitAND(GUICtrlGetState($Files), $GUI_SHOW) Then GUICtrlSetState($Files, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($LocalFile), $GUI_SHOW) Then GUICtrlSetState($LocalFile, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($Favorites), $GUI_SHOW) Then GUICtrlSetState($Favorites, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($OutlookCf), $GUI_SHOW) Then GUICtrlSetState($OutlookCf, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($DesktopCf), $GUI_SHOW) Then GUICtrlSetState($DesktopCf, $GUI_HIDE) ;if visible, then hide
    EndSwitch
    #endregion Show/Hide Backup Options
WEnd


Func _PopulateCombo($HwndCTRLID, $vInfo)
    Local $sStoreForCombo = ''
    For $iCount = 1 To UBound($vInfo) - 1
        If $vInfo[$iCount] <> '' And StringInStr($vInfo[$iCount], '.') Then $sStoreForCombo &= $vInfo[$iCount] & '|'
    Next
    GUICtrlSetData($HwndCTRLID, $sStoreForCombo)
EndFunc   ;==>_PopulateCombo

Func _Restore($iProfiles, $iFolders)

EndFunc   ;==>_Restore

Func _StartAction($iProfiles, $iFolders, $Flag)
    Local $CurrentProfile, $CurrentFolder, $Directory, $I
    If Not IsArray($iFolders) Then Return
    If Not IsArray($iProfiles) Then
        Local $nArray[1] = [$iProfiles]
    Else
        Local $nArray = $iProfiles
    EndIf
    For $CurrentProfile In $nArray
        If Not $CurrentProfile Then ContinueLoop
        If Not StringInStr($CurrentProfile, '.') Then ContinueLoop
        For $CurrentFolder = 1 To $iFolders
            Switch @OSVersion
                Case 'WIN_7'
                    Local $Folder = 'C:\Users'
                    Switch $CurrentFolder
                        Case 'Local Storage'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Documents'
                        Case 'Favorites'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Favorites'
                        Case 'Outlook'
                            $Directory = $Folder & '\' & $CurrentProfile & '\AppData\Local\Microsoft\Outlook'
                        Case 'Desktop'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Desktop'
                        Case Else
                            ContinueLoop
                    EndSwitch
                Case 'WIN_XP'
                    Local $Folder = 'C:\Documents and Settings'
                    Switch $CurrentFolder
                        Case 'Local Storage'
                            $Directory = $Folder & '\' & $CurrentProfile & '\My Documents'
                        Case 'Favorites'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Favorites'
                        Case 'Outlook'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Local Settings\Application Data\Microsoft\Outlook'
                        Case 'Desktop'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Desktop'
                        Case Else
                            ContinueLoop
                    EndSwitch
            EndSwitch
            MsgBox(0, '', '$Directory = ' & $Directory & @LF & '$BackupDir = ' & $BackupDir & StringReplace($Directory, $Folder, '') & @LF & '$Flag = ' & $Flag)
            Switch $Flag
                Case 'Backup'
                    ;If Not FileExists($Directory) Then ContinueLoop
                    _CopyFiles($Directory, $BackupDir & StringReplace($Directory, $Folder, ''))
                Case 'Restore'
                    If Not FileExists($BackupDir & StringReplace($Directory, $Folder, '')) Then ContinueLoop
                    _CopyFiles($BackupDir & StringReplace($Directory, $Folder, ''), $Directory)
            EndSwitch
        Next
    Next
    Return 1
EndFunc   ;==>_StartAction

Func _CopyFiles($Source, $Destination)
    Local $fArray, $TotalSize, $BytesCopied, $hWnd
    $fArray = _FileListToArray_Recursive($Source, '*', 1)
    If Not IsArray($fArray) Then Return

    Local $Size[UBound($fArray)][3]
    $Size[0][0] = $fArray[0]
    For $I = 1 To $fArray[0]
        $Size[$I][0] = $fArray[$I]
        $Size[$I][1] = StringReplace($Size[$I][0], $Source, $Destination)
        $Size[$I][2] = FileGetSize($fArray[$I])
        $TotalSize += $Size[$I][2]
    Next
    $Size[0][2] = $TotalSize

    ProgressOn('Progress Meter', 'Percentage of Total Bytes Completed', '0 percent')
    $hWnd = WinGetHandle('Progress Meter', '')
    WinSetOnTop($hWnd, '', 1)
    For $I = 1 To $Size[0][0]
        If Not $Size[$I][0] Or IsInt($Size[$I][0]) Then ContinueLoop
        WinSetTitle($hWnd, '', StringRegExpReplace($Size[$I][0], '^.+\\', ''))
        FileCopy($Size[$I][0], $Size[$I][1], 9)
        $BytesCopied += $Size[$I][2]
        ProgressSet(Floor(($BytesCopied / $TotalSize) * 100), Floor(($BytesCopied / $TotalSize) * 100) & ' percent')
    Next
    ProgressOff()
EndFunc   ;==>_CopyFiles


Func _FileListToArray_Recursive($sPath, $sFilter = "*", $iRetItemType = 0, $iRetPathType = 2, $bRecursive = True)
    Local $sRet = '', $sRetPath = '', $sOrigPathLen, $sCurrPathLen, $sCurrPath, $Search, $File, $hSearch
    $sPath = StringRegExpReplace($sPath, "[\\/]+\z", "")
    If Not FileExists($sPath) Then Return SetError(1, 1, "")
    If StringRegExp($sFilter, "[\\/ :> <\|]|(?s)\A\s*\z") Then Return SetError(2, 2, "")
    $sPath &= "\|"
    $sOrigPathLen = StringLen($sPath) - 1
    While $sPath
        $sCurrPathLen = StringInStr($sPath, "|") - 1
        $sCurrPath = StringLeft($sPath, $sCurrPathLen)
        $Search = FileFindFirstFile($sCurrPath & $sFilter)
        If @error Then
            $sPath = StringTrimLeft($sPath, $sCurrPathLen + 1)
            ContinueLoop
        EndIf
        Switch $iRetPathType
            Case 1 ; relative path
                $sRetPath = StringTrimLeft($sCurrPath, $sOrigPathLen)
            Case 2 ; full path
                $sRetPath = $sCurrPath
        EndSwitch
        While 1
            $File = FileFindNextFile($Search)
            If @error Then ExitLoop
            If ($iRetItemType + @extended = 2) Then ContinueLoop
            $sRet &= $sRetPath & $File & "|"
        WEnd
        FileClose($Search)
        If $bRecursive Then
            $hSearch = FileFindFirstFile($sCurrPath & "*")
            While 1
                $File = FileFindNextFile($hSearch)
                If @error Then ExitLoop
                If @extended Then $sPath &= $sCurrPath & $File & "\|"
            WEnd
            FileClose($hSearch)
        EndIf
        $sPath = StringTrimLeft($sPath, $sCurrPathLen + 1)
    WEnd
    If Not $sRet Then Return SetError(4, 4, "")
    Return StringSplit(StringTrimRight($sRet, 1), "|")
EndFunc   ;==>_FileListToArray_Recursive
Link to comment
Share on other sites

Just a little more help and this thing will be completed!

I tweaked for my environment, RESTORE function doesn't work though

How can I get this going? I know how I can configure copying the files to the right place, I just don't know how to excute the rstore...

this is the final piece

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <File.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $FileToPopulate, $UserList, $BackUp, $Restore, $Files, $LocalFile, $Favorites, $OutlookCf, $DesktopCf, $Okay, $Msg, $AllUsersSelect
Global $OutlookSet, $OutlookDat, $OutlookCfg, $OutlookReg, $OutlookSig, $OutlookSta, $OutlookN2K
Global $BackupDir = '\\File1\Transfer\UserBackups' ;change this to your backup directory

Switch @OSVersion
    Case 'WIN_7'
        RunWait('cmd /c dir /b "C:\Users" > ' & @TempDir & '\UserList', '', @SW_HIDE)
    Case 'WIN_XP'
        RunWait('cmd /c dir /b "C:\Documents and Settings" > ' & @TempDir & '\UserList', '', @SW_HIDE)
EndSwitch
$FileToPopulate = @TempDir & '\UserList'

GUICreate('BackUp/Restore User Information')
; Select User
GUICtrlCreateLabel('Select User to Backup', 25, 20, 280, 20)
$UserList = GUICtrlCreateCombo('', 25, 35, 175, 20)
$AllUsersSelect = GUICtrlCreateCheckbox('Select All Profiles', 210, 35, 105, 20)
Local $aFileArray
_FileReadToArray($FileToPopulate, $aFileArray)
_PopulateCombo($UserList, $aFileArray)
; Backup or Restore option
$BackUp = GUICtrlCreateRadio('Backup', 25, 75, 100)
GUICtrlSetState($Okay, $GUI_UNCHECKED)
$Restore = GUICtrlCreateRadio('Restore', 150, 75, 100)
GUICtrlSetState($Okay, $GUI_UNCHECKED)
; Auto populated if Backup is selected, hidden if not
$Files = GUICtrlCreateLabel('Select Files To BackUp', 25, 100, 120, 20)
GUICtrlSetState($Files, $GUI_HIDE)
$Favorites = GUICtrlCreateCheckbox('Favorites', 25, 115, 85, 20 )
GUICtrlSetState($Favorites, $GUI_HIDE)
$DesktopCf = GUICtrlCreateCheckbox('Desktop', 150, 115, 80, 20 )
GUICtrlSetState($DesktopCf, $GUI_HIDE)
$LocalFile = GUICtrlCreateCheckbox('Local Storage', 250, 115, 90, 20 )
GUICtrlSetState($LocalFile, $GUI_HIDE)
$OutlookSet = GUICtrlCreateLabel('Outlook Settings', 25, 140, 140, 20 )
GUICtrlSetState($OutlookSet, $GUI_HIDE)
$OutlookDat = GUICtrlCreateCheckbox('Data', 25, 155, 80, 20 )
GUICtrlSetState($OutlookReg, $GUI_HIDE)
$OutlookCfg = GUICtrlCreateCheckbox('Configuration', 150, 175, 80, 20)
GUICtrlSetState($OutlookCfg, $GUI_HIDE)
$OutlookSig = GUICtrlCreateCheckbox('Signature', 25, 175, 80, 20 )
GUICtrlSetState($OutlookSig, $GUI_HIDE)
$OutlookSta = GUICtrlCreateCheckbox('Stationary', 150, 155, 80, 20 )
GUICtrlSetState($OutlookSta, $GUI_HIDE)
$OutlookN2K = GUICtrlCreateCheckbox('Outlook.N2K', 25, 195, 80, 20 )
GUICtrlSetState($OutlookN2K, $GUI_HIDE)
$Okay = GUICtrlCreateButton('OK', 25, 220, 30, 20)
GUICtrlSetState($Okay, $GUI_DISABLE)
GUISetState()

While 1
    Local $ProfileList
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then ExitLoop

    #region Enable OK Button    ;enaable OK button only if Profile is selected and one of the radio buttons are selected
    If $Msg = $AllUsersSelect Then
        Switch GUICtrlRead($AllUsersSelect)
            Case $GUI_CHECKED
                GUICtrlSetData($UserList, '')
                GUICtrlSetState($UserList, $GUI_DISABLE)
            Case $GUI_UNCHECKED
                GUICtrlSetData($UserList, '')
                GUICtrlSetState($UserList, $GUI_ENABLE)
        EndSwitch
    EndIf
    If BitAND(GUICtrlGetState($Okay), $GUI_DISABLE) Then
        If BitAND(GUICtrlRead($BackUp), $GUI_CHECKED) Or BitAND(GUICtrlRead($Restore), $GUI_CHECKED) Then
            If StringRegExp(GUICtrlRead($UserList), '^[^\s]+$', 0) Or GUICtrlRead($AllUsersSelect) = $GUI_CHECKED Then
                GUICtrlSetState($Okay, $GUI_ENABLE)
            EndIf
        EndIf
    EndIf
    #endregion Enable OK Button ;enaable OK button only if Profile is selected and one of the radio buttons are selected

    #region OK Button pressed
    If $Msg = $Okay Then
        Local $Selection[1] = [0]
        If GUICtrlRead($LocalFile) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Local Storage')
        If GUICtrlRead($Favorites) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Favorites')
        If GUICtrlRead($OutlookDat) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Data')
        If GUICtrlRead($OutlookCfg) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Configuration')
        If GUICtrlRead($OutlookSig) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Signature')
        If GUICtrlRead($OutlookSta) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Stationary')
        If GUICtrlRead($OutlookN2K) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Outlook.N2K')
        If GUICtrlRead($DesktopCf) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Desktop')
        $Selection[0] = UBound($Selection) - 1
        If $Selection[0] > 0 Then
            GUISetState(@SW_HIDE) ;Hide The Main GUI
            If GUICtrlRead($BackUp) = $GUI_CHECKED Then Local $sAction = 'Backup'   ;Backup Checked
            If GUICtrlRead($Restore) = $GUI_CHECKED Then Local $sAction = 'Restore'  ;Restore Checked
            If GUICtrlRead($AllUsersSelect) = $GUI_CHECKED Then
                _StartAction($aFileArray, $Selection, $sAction)
            Else
                If GUICtrlRead($UserList) Then _StartAction(GUICtrlRead($UserList), $Selection, $sAction)
            EndIf
            GUISetState(@SW_SHOW)   ;Restore The Main GUI
        EndIf
    EndIf
    #endregion OK Button pressed

    #region Show/Hide Backup Options
    Switch GUICtrlRead($BackUp)
        Case $GUI_CHECKED ;Backup checked
            If BitAND(GUICtrlGetState($Files), $GUI_HIDE) Then GUICtrlSetState($Files, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($LocalFile), $GUI_HIDE) Then GUICtrlSetState($LocalFile, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($Favorites), $GUI_HIDE) Then GUICtrlSetState($Favorites, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($OutlookSet), $GUI_HIDE) Then GUICtrlSetState($OutlookSet, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($OutlookDat), $GUI_HIDE) Then GUICtrlSetState($OutlookDat, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($OutlookCfg), $GUI_HIDE) Then GUICtrlSetState($OutlookCfg, $GUI_SHOW) ;if hidden, then showe
            If BitAND(GUICtrlGetState($OutlookSig), $GUI_HIDE) Then GUICtrlSetState($OutlookSig, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($OutlookSta), $GUI_HIDE) Then GUICtrlSetState($OutlookSta, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($OutlookN2K), $GUI_HIDE) Then GUICtrlSetState($OutlookN2K, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($DesktopCf), $GUI_HIDE) Then GUICtrlSetState($DesktopCf, $GUI_SHOW) ;if hidden, then show
        Case Else ;Backup not checked
            If BitAND(GUICtrlGetState($Files), $GUI_SHOW) Then GUICtrlSetState($Files, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($LocalFile), $GUI_SHOW) Then GUICtrlSetState($LocalFile, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($Favorites), $GUI_SHOW) Then GUICtrlSetState($Favorites, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($OutlookSet), $GUI_SHOW) Then GUICtrlSetState($OutlookSet, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($OutlookDat), $GUI_SHOW) Then GUICtrlSetState($OutlookDat, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($OutlookCfg), $GUI_SHOW) Then GUICtrlSetState($OutlookCfg, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($OutlookSig), $GUI_SHOW) Then GUICtrlSetState($OutlookSig, $GUI_HIDE) ;if wisible, then hide
            If BitAND(GUICtrlGetState($OutlookSta), $GUI_SHOW) Then GUICtrlSetState($OutlookSta, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($OutlookN2K), $GUI_SHOW) Then GUICtrlSetState($OutlookN2K, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($DesktopCf), $GUI_SHOW) Then GUICtrlSetState($DesktopCf, $GUI_HIDE) ;if visible, then hide
    EndSwitch
    #endregion Show/Hide Backup Options
WEnd


Func _PopulateCombo($HwndCTRLID, $vInfo)
    Local $sStoreForCombo = ''
    For $iCount = 1 To UBound($vInfo) - 1
        If $vInfo[$iCount] <> '' And StringInStr($vInfo[$iCount], '.') Then $sStoreForCombo &= $vInfo[$iCount] & '|'
    Next
    GUICtrlSetData($HwndCTRLID, $sStoreForCombo)
EndFunc   ;==>_PopulateCombo

Func _Restore($iProfiles, $iFolders)
MsgBox ( 0, '', 'Message' )
EndFunc   ;==>_Restore

Func _StartAction($iProfiles, $iFolders, $Flag)
    Local $CurrentProfile, $CurrentFolder, $Directory, $I
    If Not IsArray($iFolders) Then Return
    If Not IsArray($iProfiles) Then
        Local $nArray[1] = [$iProfiles]
    Else
        Local $nArray = $iProfiles
    EndIf
    For $CurrentProfile In $nArray
        If Not $CurrentProfile Then ContinueLoop
        If Not StringInStr($CurrentProfile, '.') Then ContinueLoop
        For $CurrentFolder = 1 To $iFolders
            Switch @OSVersion
                Case 'WIN_7'
                    Local $Folder = 'C:\Users'
                    Switch $CurrentFolder
                        Case 'Local Storage'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Documents'
                        Case 'Favorites'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Favorites'
                        Case 'Outlook'
                            $Directory = $Folder & '\' & $CurrentProfile & '\AppData\Local\Microsoft\Outlook'
                        Case 'Desktop'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Desktop'
                        Case Else
                            ContinueLoop
                    EndSwitch
                Case 'WIN_XP'
                    Local $Folder = 'C:\Documents and Settings', $LocalStorage = 'C:\Local Storage'
                    Switch $CurrentFolder
                        Case 'Local Storage'
                            DirCopy ( $LocalStorage & '\' & $CurrentProfile, $BackupDir & '\' & $CurrentProfile & '\' & '\' & 'LocalStorage', 1 )
                        Case 'Favorites'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Favorites'
                        Case 'Data'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Local Settings\Application Data\Microsoft\Outlook'
                        Case 'Configuration'
                            RunWait ( 'reg export "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook" ' & $BackupDir & '\' & $CurrentProfile & '\Outlook\Profile.reg', '', @SW_HIDE )
                        Case 'Signature'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Application Data\Microsoft\Signatures'
                        Case 'Stationary'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Application Data\Microsoft\Stationery'
                        Case 'Outlook.N2K'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Application Data\Microsoft\Outlook'
                        Case 'Desktop'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Desktop'
                        Case Else
                            ContinueLoop
                    EndSwitch
            EndSwitch
            ;MsgBox ( 0, '', '$Directory = ' & ' ' & $LocalStorage & '\' & $CurrentProfile & @LF & '$BackupDir = ' & $BackupDir & '\' & $CurrentProfile );MsgBox(0, '', '$Directory = ' & $Directory & @LF & '$BackupDir = ' & $BackupDir & StringReplace($Directory, $Folder, '') & @LF & '$Flag = ' & $Flag)
            Switch $Flag
                Case 'Backup'
                    ;If Not FileExists($Directory) Then ContinueLoop
                    _CopyFiles($Directory, $BackupDir & StringReplace($Directory, $Folder, ''))
                Case 'Restore'
                    ;If Not FileExists($BackupDir & StringReplace($Directory, $Folder, '')) Then ContinueLoop
                    MsgBox ( 0, '', 'Copy The Files' );_CopyFiles($BackupDir & StringReplace($Directory, $Folder, ''), $Directory)
            EndSwitch
        Next
    Next
    Return 1
EndFunc   ;==>_StartAction

Func _CopyFiles($Source, $Destination)
    Local $fArray, $TotalSize, $BytesCopied, $hWnd
    $fArray = _FileListToArray_Recursive($Source, '*', 1)
    If Not IsArray($fArray) Then Return

    Local $Size[UBound($fArray)][3]
    $Size[0][0] = $fArray[0]
    For $I = 1 To $fArray[0]
        $Size[$I][0] = $fArray[$I]
        $Size[$I][1] = StringReplace($Size[$I][0], $Source, $Destination)
        $Size[$I][2] = FileGetSize($fArray[$I])
        $TotalSize += $Size[$I][2]
    Next
    $Size[0][2] = $TotalSize

    ProgressOn('Progress Meter', 'Percentage of Total Bytes Completed', '0 percent')
    $hWnd = WinGetHandle('Progress Meter', '')
    WinSetOnTop($hWnd, '', 1)
    For $I = 1 To $Size[0][0]
        If Not $Size[$I][0] Or IsInt($Size[$I][0]) Then ContinueLoop
        WinSetTitle($hWnd, '', StringRegExpReplace($Size[$I][0], '^.+\\', ''))
        FileCopy($Size[$I][0], $Size[$I][1], 9)
        $BytesCopied += $Size[$I][2]
        ProgressSet(Floor(($BytesCopied / $TotalSize) * 100), Floor(($BytesCopied / $TotalSize) * 100) & ' percent')
    Next
    ProgressOff()
EndFunc   ;==>_CopyFiles


Func _FileListToArray_Recursive($sPath, $sFilter = "*", $iRetItemType = 0, $iRetPathType = 2, $bRecursive = True)
    Local $sRet = '', $sRetPath = '', $sOrigPathLen, $sCurrPathLen, $sCurrPath, $Search, $File, $hSearch
    $sPath = StringRegExpReplace($sPath, "[\\/]+\z", "")
    If Not FileExists($sPath) Then Return SetError(1, 1, "")
    If StringRegExp($sFilter, "[\\/ :> <\|]|(?s)\A\s*\z") Then Return SetError(2, 2, "")
    $sPath &= "\|"
    $sOrigPathLen = StringLen($sPath) - 1
    While $sPath
        $sCurrPathLen = StringInStr($sPath, "|") - 1
        $sCurrPath = StringLeft($sPath, $sCurrPathLen)
        $Search = FileFindFirstFile($sCurrPath & $sFilter)
        If @error Then
            $sPath = StringTrimLeft($sPath, $sCurrPathLen + 1)
            ContinueLoop
        EndIf
        Switch $iRetPathType
            Case 1 ; relative path
                $sRetPath = StringTrimLeft($sCurrPath, $sOrigPathLen)
            Case 2 ; full path
                $sRetPath = $sCurrPath
        EndSwitch
        While 1
            $File = FileFindNextFile($Search)
            If @error Then ExitLoop
            If ($iRetItemType + @extended = 2) Then ContinueLoop
            $sRet &= $sRetPath & $File & "|"
        WEnd
        FileClose($Search)
        If $bRecursive Then
            $hSearch = FileFindFirstFile($sCurrPath & "*")
            While 1
                $File = FileFindNextFile($hSearch)
                If @error Then ExitLoop
                If @extended Then $sPath &= $sCurrPath & $File & "\|"
            WEnd
            FileClose($hSearch)
        EndIf
        $sPath = StringTrimLeft($sPath, $sCurrPathLen + 1)
    WEnd
    If Not $sRet Then Return SetError(4, 4, "")
    Return StringSplit(StringTrimRight($sRet, 1), "|")
EndFunc   ;==>_FileListToArray_Recursive
Link to comment
Share on other sites

Try this...I messed up and required that the $Selection Array be greater than 0, but it cannot be defined if you click the restore radiobox...I also corrected the repopulating of the userlist if All Users was unchecked. Little mistakes, but we're getting there.

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <File.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $FileToPopulate, $UserList, $BackUp, $Restore, $Files, $LocalFile, $Favorites, $OutlookCf, $DesktopCf, $Okay, $Msg, $AllUsersSelect
Global $OutlookSet, $OutlookDat, $OutlookCfg, $OutlookReg, $OutlookSig, $OutlookSta, $OutlookN2K
Global $BackupDir = '\\File1\Transfer\UserBackups' ;change this to your backup directory

Switch @OSVersion
    Case 'WIN_7'
        RunWait('cmd /c dir /b "C:\Users" > ' & @TempDir & '\UserList', '', @SW_HIDE)
    Case 'WIN_XP'
        RunWait('cmd /c dir /b "C:\Documents and Settings" > ' & @TempDir & '\UserList', '', @SW_HIDE)
EndSwitch
$FileToPopulate = @TempDir & '\UserList'

GUICreate('BackUp/Restore User Information')
; Select User
GUICtrlCreateLabel('Select User to Backup', 25, 20, 280, 20)
$UserList = GUICtrlCreateCombo('', 25, 35, 175, 20)
$AllUsersSelect = GUICtrlCreateCheckbox('Select All Profiles', 210, 35, 105, 20)
Local $aFileArray
_FileReadToArray($FileToPopulate, $aFileArray)
_PopulateCombo($UserList, $aFileArray)
; Backup or Restore option
$BackUp = GUICtrlCreateRadio('Backup', 25, 75, 100)
GUICtrlSetState($Okay, $GUI_UNCHECKED)
$Restore = GUICtrlCreateRadio('Restore', 150, 75, 100)
GUICtrlSetState($Okay, $GUI_UNCHECKED)
; Auto populated if Backup is selected, hidden if not
$Files = GUICtrlCreateLabel('Select Files To BackUp', 25, 100, 120, 20)
GUICtrlSetState($Files, $GUI_HIDE)
$Favorites = GUICtrlCreateCheckbox('Favorites', 25, 115, 85, 20)
GUICtrlSetState($Favorites, $GUI_HIDE)
$DesktopCf = GUICtrlCreateCheckbox('Desktop', 150, 115, 80, 20)
GUICtrlSetState($DesktopCf, $GUI_HIDE)
$LocalFile = GUICtrlCreateCheckbox('Local Storage', 250, 115, 90, 20)
GUICtrlSetState($LocalFile, $GUI_HIDE)
$OutlookSet = GUICtrlCreateLabel('Outlook Settings', 25, 140, 140, 20)
GUICtrlSetState($OutlookSet, $GUI_HIDE)
$OutlookDat = GUICtrlCreateCheckbox('Data', 25, 155, 80, 20)
GUICtrlSetState($OutlookReg, $GUI_HIDE)
$OutlookCfg = GUICtrlCreateCheckbox('Configuration', 150, 175, 80, 20)
GUICtrlSetState($OutlookCfg, $GUI_HIDE)
$OutlookSig = GUICtrlCreateCheckbox('Signature', 25, 175, 80, 20)
GUICtrlSetState($OutlookSig, $GUI_HIDE)
$OutlookSta = GUICtrlCreateCheckbox('Stationary', 150, 155, 80, 20)
GUICtrlSetState($OutlookSta, $GUI_HIDE)
$OutlookN2K = GUICtrlCreateCheckbox('Outlook.N2K', 25, 195, 80, 20)
GUICtrlSetState($OutlookN2K, $GUI_HIDE)
$Okay = GUICtrlCreateButton('OK', 25, 220, 30, 20)
GUICtrlSetState($Okay, $GUI_DISABLE)
GUISetState()

While 1
    Local $ProfileList
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then ExitLoop

    #region Enable OK Button    ;enaable OK button only if Profile is selected and one of the radio buttons are selected
    If $Msg = $AllUsersSelect Then
        Switch GUICtrlRead($AllUsersSelect)
            Case $GUI_CHECKED
                GUICtrlSetData($UserList, '')
                GUICtrlSetState($UserList, $GUI_DISABLE)
            Case $GUI_UNCHECKED
                _PopulateCombo($UserList, $aFileArray)
                GUICtrlSetState($UserList, $GUI_ENABLE)
        EndSwitch
    EndIf
    If BitAND(GUICtrlGetState($Okay), $GUI_DISABLE) Then
        If BitAND(GUICtrlRead($BackUp), $GUI_CHECKED) Or BitAND(GUICtrlRead($Restore), $GUI_CHECKED) Then
            If StringRegExp(GUICtrlRead($UserList), '^[^\s]+$', 0) Or GUICtrlRead($AllUsersSelect) = $GUI_CHECKED Then
                GUICtrlSetState($Okay, $GUI_ENABLE)
            EndIf
        EndIf
    EndIf
    #endregion Enable OK Button    ;enaable OK button only if Profile is selected and one of the radio buttons are selected

    #region OK Button pressed
    If $Msg = $Okay Then
        GUISetState(@SW_HIDE) ;Hide The Main GUI
        If GUICtrlRead($Restore) = $GUI_CHECKED Then ;Restore Checked
            Local $sAction = 'Restore'
            Local $Selection[9] = [8, 'Local Storage', 'Favorites', 'Data', 'Configuration', 'Signature', 'Stationary', 'Outlook.N2K', 'Desktop']
        ElseIf GUICtrlRead($BackUp) = $GUI_CHECKED Then
            Local $Selection[1] = [0]
            If GUICtrlRead($LocalFile) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Local Storage')
            If GUICtrlRead($Favorites) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Favorites')
            If GUICtrlRead($OutlookDat) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Data')
            If GUICtrlRead($OutlookCfg) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Configuration')
            If GUICtrlRead($OutlookSig) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Signature')
            If GUICtrlRead($OutlookSta) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Stationary')
            If GUICtrlRead($OutlookN2K) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Outlook.N2K')
            If GUICtrlRead($DesktopCf) = $GUI_CHECKED Then _ArrayAdd($Selection, 'Desktop')
            $Selection[0] = UBound($Selection) - 1
            Local $sAction = 'Backup' ;Backup Checked
            If $Selection[0] = 0 Then
                GUISetState(@SW_SHOW) ;Restore The Main GUI
                ContinueLoop
            EndIf
        EndIf
        If GUICtrlRead($AllUsersSelect) = $GUI_CHECKED Then
            _StartAction($aFileArray, $Selection, $sAction)
        Else
            If GUICtrlRead($UserList) Then _StartAction(GUICtrlRead($UserList), $Selection, $sAction)
        EndIf
        GUISetState(@SW_SHOW) ;Restore The Main GUI
    EndIf
    #endregion OK Button pressed

    #region Show/Hide Backup Options
    Switch GUICtrlRead($BackUp)
        Case $GUI_CHECKED ;Backup checked
            If BitAND(GUICtrlGetState($Files), $GUI_HIDE) Then GUICtrlSetState($Files, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($LocalFile), $GUI_HIDE) Then GUICtrlSetState($LocalFile, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($Favorites), $GUI_HIDE) Then GUICtrlSetState($Favorites, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($OutlookSet), $GUI_HIDE) Then GUICtrlSetState($OutlookSet, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($OutlookDat), $GUI_HIDE) Then GUICtrlSetState($OutlookDat, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($OutlookCfg), $GUI_HIDE) Then GUICtrlSetState($OutlookCfg, $GUI_SHOW) ;if hidden, then showe
            If BitAND(GUICtrlGetState($OutlookSig), $GUI_HIDE) Then GUICtrlSetState($OutlookSig, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($OutlookSta), $GUI_HIDE) Then GUICtrlSetState($OutlookSta, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($OutlookN2K), $GUI_HIDE) Then GUICtrlSetState($OutlookN2K, $GUI_SHOW) ;if hidden, then show
            If BitAND(GUICtrlGetState($DesktopCf), $GUI_HIDE) Then GUICtrlSetState($DesktopCf, $GUI_SHOW) ;if hidden, then show
        Case Else ;Backup not checked
            If BitAND(GUICtrlGetState($Files), $GUI_SHOW) Then GUICtrlSetState($Files, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($LocalFile), $GUI_SHOW) Then GUICtrlSetState($LocalFile, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($Favorites), $GUI_SHOW) Then GUICtrlSetState($Favorites, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($OutlookSet), $GUI_SHOW) Then GUICtrlSetState($OutlookSet, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($OutlookDat), $GUI_SHOW) Then GUICtrlSetState($OutlookDat, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($OutlookCfg), $GUI_SHOW) Then GUICtrlSetState($OutlookCfg, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($OutlookSig), $GUI_SHOW) Then GUICtrlSetState($OutlookSig, $GUI_HIDE) ;if wisible, then hide
            If BitAND(GUICtrlGetState($OutlookSta), $GUI_SHOW) Then GUICtrlSetState($OutlookSta, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($OutlookN2K), $GUI_SHOW) Then GUICtrlSetState($OutlookN2K, $GUI_HIDE) ;if visible, then hide
            If BitAND(GUICtrlGetState($DesktopCf), $GUI_SHOW) Then GUICtrlSetState($DesktopCf, $GUI_HIDE) ;if visible, then hide
    EndSwitch
    #endregion Show/Hide Backup Options
WEnd


Func _PopulateCombo($HwndCTRLID, $vInfo)
    Local $sStoreForCombo = ''
    For $iCount = 1 To UBound($vInfo) - 1
        If $vInfo[$iCount] <> '' And StringInStr($vInfo[$iCount], '.') Then $sStoreForCombo &= $vInfo[$iCount] & '|'
    Next
    GUICtrlSetData($HwndCTRLID, $sStoreForCombo)
EndFunc   ;==>_PopulateCombo

Func _Restore($iProfiles, $iFolders)
    MsgBox(0, '', 'Message')
EndFunc   ;==>_Restore

Func _StartAction($iProfiles, $iFolders, $Flag)
    Local $CurrentProfile, $CurrentFolder, $Directory, $I
    If Not IsArray($iFolders) Then Return
    If Not IsArray($iProfiles) Then
        Local $nArray[1] = [$iProfiles]
    Else
        Local $nArray = $iProfiles
    EndIf
    For $CurrentProfile In $nArray
        If Not $CurrentProfile Then ContinueLoop
        If Not StringInStr($CurrentProfile, '.') Then ContinueLoop
        For $CurrentFolder = 1 To $iFolders
            Switch @OSVersion
                Case 'WIN_7'
                    Local $Folder = 'C:\Users'
                    Switch $CurrentFolder
                        Case 'Local Storage'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Documents'
                        Case 'Favorites'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Favorites'
                        Case 'Outlook'
                            $Directory = $Folder & '\' & $CurrentProfile & '\AppData\Local\Microsoft\Outlook'
                        Case 'Desktop'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Desktop'
                        Case Else
                            ContinueLoop
                    EndSwitch
                Case 'WIN_XP'
                    Local $Folder = 'C:\Documents and Settings', $LocalStorage = 'C:\Local Storage'
                    Switch $CurrentFolder
                        Case 'Local Storage'
                            DirCopy($LocalStorage & '\' & $CurrentProfile, $BackupDir & '\' & $CurrentProfile & '\' & '\' & 'LocalStorage', 1)
                        Case 'Favorites'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Favorites'
                        Case 'Data'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Local Settings\Application Data\Microsoft\Outlook'
                        Case 'Configuration'
                            RunWait('reg export "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook" ' & $BackupDir & '\' & $CurrentProfile & '\Outlook\Profile.reg', '', @SW_HIDE)
                        Case 'Signature'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Application Data\Microsoft\Signatures'
                        Case 'Stationary'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Application Data\Microsoft\Stationery'
                        Case 'Outlook.N2K'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Application Data\Microsoft\Outlook'
                        Case 'Desktop'
                            $Directory = $Folder & '\' & $CurrentProfile & '\Desktop'
                        Case Else
                            ContinueLoop
                    EndSwitch
            EndSwitch
            ;MsgBox ( 0, '', '$Directory = ' & ' ' & $LocalStorage & '\' & $CurrentProfile & @LF & '$BackupDir = ' & $BackupDir & '\' & $CurrentProfile );MsgBox(0, '', '$Directory = ' & $Directory & @LF & '$BackupDir = ' & $BackupDir & StringReplace($Directory, $Folder, '') & @LF & '$Flag = ' & $Flag)
            Switch $Flag
                Case 'Backup'
                    ;If Not FileExists($Directory) Then ContinueLoop
                    _CopyFiles($Directory, $BackupDir & StringReplace($Directory, $Folder, ''))
                Case 'Restore'
                    ;If Not FileExists($BackupDir & StringReplace($Directory, $Folder, '')) Then ContinueLoop
                    MsgBox(0, '', 'Copy The Files');_CopyFiles($BackupDir & StringReplace($Directory, $Folder, ''), $Directory)
            EndSwitch
        Next
    Next
    Return 1
EndFunc   ;==>_StartAction

Func _CopyFiles($Source, $Destination)
    Local $fArray, $TotalSize, $BytesCopied, $hWnd
    $fArray = _FileListToArray_Recursive($Source, '*', 1)
    If Not IsArray($fArray) Then Return

    Local $Size[UBound($fArray)][3]
    $Size[0][0] = $fArray[0]
    For $I = 1 To $fArray[0]
        $Size[$I][0] = $fArray[$I]
        $Size[$I][1] = StringReplace($Size[$I][0], $Source, $Destination)
        $Size[$I][2] = FileGetSize($fArray[$I])
        $TotalSize += $Size[$I][2]
    Next
    $Size[0][2] = $TotalSize

    ProgressOn('Progress Meter', 'Percentage of Total Bytes Completed', '0 percent')
    $hWnd = WinGetHandle('Progress Meter', '')
    WinSetOnTop($hWnd, '', 1)
    For $I = 1 To $Size[0][0]
        If Not $Size[$I][0] Or IsInt($Size[$I][0]) Then ContinueLoop
        WinSetTitle($hWnd, '', StringRegExpReplace($Size[$I][0], '^.+\\', ''))
        FileCopy($Size[$I][0], $Size[$I][1], 9)
        $BytesCopied += $Size[$I][2]
        ProgressSet(Floor(($BytesCopied / $TotalSize) * 100), Floor(($BytesCopied / $TotalSize) * 100) & ' percent')
    Next
    ProgressOff()
EndFunc   ;==>_CopyFiles


Func _FileListToArray_Recursive($sPath, $sFilter = "*", $iRetItemType = 0, $iRetPathType = 2, $bRecursive = True)
    Local $sRet = '', $sRetPath = '', $sOrigPathLen, $sCurrPathLen, $sCurrPath, $Search, $File, $hSearch
    $sPath = StringRegExpReplace($sPath, "[\\/]+\z", "")
    If Not FileExists($sPath) Then Return SetError(1, 1, "")
    If StringRegExp($sFilter, "[\\/ :> <\|]|(?s)\A\s*\z") Then Return SetError(2, 2, "")
    $sPath &= "\|"
    $sOrigPathLen = StringLen($sPath) - 1
    While $sPath
        $sCurrPathLen = StringInStr($sPath, "|") - 1
        $sCurrPath = StringLeft($sPath, $sCurrPathLen)
        $Search = FileFindFirstFile($sCurrPath & $sFilter)
        If @error Then
            $sPath = StringTrimLeft($sPath, $sCurrPathLen + 1)
            ContinueLoop
        EndIf
        Switch $iRetPathType
            Case 1 ; relative path
                $sRetPath = StringTrimLeft($sCurrPath, $sOrigPathLen)
            Case 2 ; full path
                $sRetPath = $sCurrPath
        EndSwitch
        While 1
            $File = FileFindNextFile($Search)
            If @error Then ExitLoop
            If ($iRetItemType + @extended = 2) Then ContinueLoop
            $sRet &= $sRetPath & $File & "|"
        WEnd
        FileClose($Search)
        If $bRecursive Then
            $hSearch = FileFindFirstFile($sCurrPath & "*")
            While 1
                $File = FileFindNextFile($hSearch)
                If @error Then ExitLoop
                If @extended Then $sPath &= $sCurrPath & $File & "\|"
            WEnd
            FileClose($hSearch)
        EndIf
        $sPath = StringTrimLeft($sPath, $sCurrPathLen + 1)
    WEnd
    If Not $sRet Then Return SetError(4, 4, "")
    Return StringSplit(StringTrimRight($sRet, 1), "|")
EndFunc   ;==>_FileListToArray_Recursive
Edited by Varian
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...