Jump to content

Combobox folder selection


rothgar
 Share

Recommended Posts

Hello everyone,

I am trying to make a autoit script for doing a computer refresh for my work (transferring a user profile from one machine to another). We are using USMT for the actual transferring and I think I have most things figured out except on a way to select the user to transfer. In the past we have just typed the username in manually but that has caused some problems with typo's and such. I wanted to have either the option to have a combobox have a option of which user to migrate (by reading what folders exist in C:\Documents and settings\ and are not Administrator or Default User) or if there is a way to select a user based on other criteria (last logged in user, etc.) I am not sure if XP has this but I know there is also a profile list in the registry for Vista but I am still a little unclear on how to make that a option on a combobox.

If anyone can be of assistance I would greatly appreciate it because I am not nearly as familiar with autoit as I would like to be.

If you have any questions of what I am trying to accomplish feel free to ask and I will respond as soon as I get the chance.

Thanks again!

Link to comment
Share on other sites

This is doing exactly what you want - it's a good start and it is up to you to make it do whatever you want.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 171, 98, 193, 125)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Combo1 = GUICtrlCreateCombo("Select", 16, 16, 137, 25)
GUICtrlSetOnEvent(-1, "Combo1Change")
$Button1 = GUICtrlCreateButton("GetUsers", 40, 56, 89, 25, 0)
GUICtrlSetOnEvent(-1, "Button1Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
    Sleep(100)
WEnd

Func Button1Click()
    Local $combo_string = ""    ;the string used to populate the combo
    $FolderList = _FileListToArray("C:\Documents and Settings", "*", 2);get folder list
    For $i = 1 To $FolderList[0]
        Switch $FolderList[$i]
            Case "All Users","Default User", "LocalService", "NetworkService";filter common dirs
                ContinueLoop
            Case Else
                If $i = $FolderList[0] Then
                    $combo_string &= $FolderList[$i]    ;if it's the last element
                Else
                    $combo_string &= $FolderList[$i]&"|"
                EndIf
        EndSwitch
    Next
    GUICtrlSetData($Combo1, $combo_string)  ;update the combo content
EndFunc
Func Combo1Change()
    MsgBox(0, "Selected", GUICtrlRead($Combo1));what happens when you change the content
EndFunc
Func Form1Close()
    Exit
EndFunc

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

That is for sure, However I seem to have ran it in a lil problem. Don't really want the code, more of a possible explanation as to why or why my code will not function. I'm a tech with small coding skills mostly simple basic stuff comparable to dos commands.

$Author = "IT Microsystems Technicians" & @LF & "    Profile Backup Tool" & @LF & "          Version 1.2" & @CRLF & "            Created by " & @LF & "        Jason Morgan"
$me = StringAddCR($Author)
Dim $test,

; Script Start - Add your code below here

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>
#include <AVIConstants.au3>
#include <TreeViewConstants.au3>

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Profile Copier", 330, 250, 308, 272)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Combo1 = GUICtrlCreateCombo("", 8, 40, 113, 25)
    GUICtrlSetOnEvent(-1, "Combo1Change")
$Button1 = GUICtrlCreateButton("Get User", 24, 80, 73, 25, 0)
    GUICtrlSetOnEvent(-1, "Button1Click")
$Button2 = GUICtrlCreateButton("Backup", 24, 128, 75, 25, 0)
    GUICtrlSetOnEvent(-1, "BackupClick")
$Exit = GUICtrlCreateButton("Exit", 128, 200, 65, 25, 0)
    GUICtrlSetOnEvent(-1, "Exitclick")

    GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

; ----------------------------------------Men creation starts here----------------------------------------;     
    $File = GuiCtrlCreateMenu("File")
    $helpmenu = GuiCtrlCreateMenu ("?")
    $aboutitem = GuiCtrlCreateMenuitem ("About",$helpmenu)
        GUICtrlSetOnEvent(-1, "Aboutclick")
; ----------------------------------------Men creation ends here----------------------------------------;       

While 1
    Sleep(100)
WEnd


Func Button1Click()
    Local $combo_string = ""   ;the string used to populate the combo
    $FolderList = _FileListToArray("C:\Documents and Settings", "*", 2);get folder list
    For $i = 1 To $FolderList[0]
        Switch $FolderList[$i]
            Case "All Users","Default User", "LocalService", "NetworkService";filter common dirs
                ContinueLoop
            Case Else
                If $i = $FolderList[0] Then
                    $combo_string &= $FolderList[$i]   ;if it's the last element
                Else
                    $combo_string &= $FolderList[$i]&"|"
                EndIf
        EndSwitch
    Next
$test = GUICtrlSetData($Combo1, $combo_string)   ;update the combo content
EndFunc


Func Combo1Change()
    MsgBox(0, "Selected", GUICtrlRead($Combo1));what happens when you change the content
EndFunc

Func BackupClick()
    DirCopy ($test, "C:\test\", 1)
EndFunc

Func Exitclick()
     Exit
EndFunc

Func Form1Close()
     Exit
EndFunc

Func Aboutclick()
     Msgbox(0,"About", $me  )
EndFunc

Basically I am trying to tell function backupclick to take the directory and copy it to a new location. I have tried to capture the values in $test (combo1 & combo_string), tried to with $folderlist, etc... I know it is my logic in understanding how to capture the data from the array that is the flaw.

Can someone point me in the right area to read up on?

Thanks

Go farther, go further, Go Harder,Is that not why we came?And if not then why bother?

Link to comment
Share on other sites

I'm a little unclear what you're trying to do with the $test variable. It just contains the boolean result of the GUICtrlSetData function, and will either be set to "1" upon success, or "0" upon failure.

Should your DirCopy be more like:

DirCopy ("C:\Documents and Settings\" & $combo_string, "C:\test", 1)
? Edited by Spiff59
Link to comment
Share on other sites

It is a small mistake in your code ( we all make mistakes) ;)

As Spiff59 pointed out - $test variable will be either 0 or 1 because this is the return of GuiCtrlSetData.

You have to remove the "$test = " part and to change the DirCopy command as follows:

The selected content of your combo is the name of the folder - you have to use GUICtrlRead to get the folder name.

DirCopy ("C:\Documents and Settings\" & GUICtrlRead($Combo1) , "C:\test", 1)

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Basically Spiff59, my logic was that $test would hold the value(s) of what $combo or $combo_string were and paste it in the directory of test. More or less I was doing a try and error process and seeing what was the result. In the end, nothing seemed to happen so I was stumped.

I had tried the:

DirCopy ("C:\Documents and Settings\" & $combo_string, "C:\test", 1)

and

DirCopy ("C:\Documents and Settings\" & $combo, "C:\test", 1)

but neither produced anything, just error in my coding. It was only until enaiman posted the GUICtrlRead code that i understood what was happening. I really need to get a deeper understanding on how this coding works.

either way I got my code to work fine except for when it tries to copy the currently logged in user's profile, which is probally due to a file in use message that windows creates. not 100% sure but the logic is there. Now to create a v1.2 where the user will get to choose where to place the files themselves rather than have a default location and make the interface a bit cleaner.

Thanks again to the both of you!

;)

:D

Edited by gemineyez

Go farther, go further, Go Harder,Is that not why we came?And if not then why bother?

Link to comment
Share on other sites

where the user will get to choose where to place the files themselves rather than have a default location

FileSelectFolder

I really need to get a deeper understanding on how this coding works.

Hehe ... welcome to the club, buddy ;)

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Well here is the almost finished product of what I started.

Just need to work a bit more on the progress bar, but I do like it.

did not want to paste the whole thing so I will only place the coding for the progress bar here and the whole code will just be an attachment.

Hope it helps others out there if they are in the same boat.

;-----------------------------------Button1 Function--------------------------------------------
Func Button1Click()
    Local $combo_string = ""                                                            ;the string used to populate the combo
    $FolderList = _FileListToArray("C:\Documents and Settings", "*", 2)                 ;get folder list
    For $i = 1 To $FolderList[0]
        Switch $FolderList[$i]
            Case "All Users","Default User", "LocalService", "NetworkService"           ;filter common dirs
                ContinueLoop
            Case Else
                If $i = $FolderList[0] Then
                    $combo_string &= $FolderList[$i]                                    ;if it's the last element
                Else
                    $combo_string &= $FolderList[$i]&"|"
                EndIf
        EndSwitch
    Next
    GUICtrlSetData($Combo1, $combo_string)                                              ;update the combo content
EndFunc
;-----------------------------------End of Button1 Function--------------------------------------------


;-----------------------------------Combo1 Function--------------------------------------------
Func Combo1Change()
    MsgBox(0, "Profile Selected", GUICtrlRead($Combo1))                                 ;what happens when you change the content
EndFunc
;-----------------------------------End of Combo1 Function--------------------------------------------

$profile = GUICtrlRead($Combo1)
;------------------------------------Backup Button Function-------------------------------------------
Func BackupClick()
    
    
    $MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"
    $var = FileSaveDialog( "Choose a name.", "C:\", "All (*.*)" , 2)            ;Allows the user to choose where to save files to (default is ...)
        
        If @error Then
    MsgBox(4096,"","Save cancelled.")
        Else
    $Confirm = MsgBox(3+32,"Confirm"," " & $var)
            if $Confirm = 7 Then
                Exit
            Else
    
                                    ;------------------------------------Progress Bar-------------------------------------------;
            $From = GUICtrlRead($Combo1)
                ProgressOn("Progress Meter" ,"Copying " & $From & " profile ", "Destination is " & $var)
            For $INDEX = 1 To $FolderList[0]
            $success = DirCopy ("C:\Documents and Settings\" & GUICtrlRead($Combo1) , $var, 1)  ;Performs a directory copy to the user specified directory location
                ProgressSet($INDEX*100/Number($FolderList[0]), "")
            Next
            ProgressOff()
        EndIf
        
        ;------------------------------------Progress Bar-------------------------------------------;
        EndIf

Any feedback would be appreciated good and bad..... if it is ugly tell me so I can do what it takes to make a real nice clean app worthy of everyone.

profile_copier_2.2.au3

Edited by gemineyez

Go farther, go further, Go Harder,Is that not why we came?And if not then why bother?

Link to comment
Share on other sites

  • 2 weeks later...

You can't really put a progress bar around a single (DirCopy) command. The bar's just gonna go from 0% to 100% in one big chunk. Nested in that loop it's just performing the same DirCopy multiple times.

I'd probably put your error-checking/retry code in a single loop to make it a little simpler, like:

While 1 
        $success = DirCopy ("C:\Documents and Settings\" & GUICtrlRead($Combo1) , $var, 1)              
        If $success Then
            $size = DirGetSize("C:\Documents and Settings\" & GUICtrlRead($Combo1))
            Msgbox(0, "status", "Original file Size is (MegaBytes):" & Round($size / 1024 / 1024))
            $test = DirGetSize("C:\profiles\" & GUICtrlRead($Combo1))
            Msgbox(0, "status", "Transfer successful, file size is (MegaBytes):" & Round($size / 1024 / 1024))
            Exitloop
        Else    
            $retry = MsgBox(5, "status", "Transfer error")
            If $retry <> 4 Then
                $retry = MsgBox(16, "status", "Transfer cancelled")
                Exitloop
            EndIf   
        EndIf
    WEnd
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...