Sign in to follow this  
Followers 0
HumperHard

issue with progress bar

9 posts in this topic

I cant get the progress bar to move besides when I click the close button. How do you set it so it will update as its completing task within the script?

#include <Array.au3>
#include <File.au3>
#include <GuiConstantsEx.au3>
#include <Misc.au3>

_Singleton("CreateUser")

; #########################################################################################
; # Create GUI
; #########################################################################################

GUICreate("Account Creation", 300, 300)

; PROGRESS

$progress = 0

$progressbar = GUICtrlCreateProgress(10, 10, 200, 20)
;GuiCtrlCreateProgress(60, 80, 150, 20)
GuiCtrlSetData($progressbar, $progress)
$label = GuiCtrlCreateLabel("Progress:", 5, 82)
GuiSetState(@SW_SHOW)

; #########################################################################################
; # GUI MESSAGE LOOP
; #########################################################################################


While 1
    if GUICtrlRead($progressbar)<>$progress Then
        GUICtrlSetData($progressbar, $progress)
    EndIf
    
    $msg = GUIGetMsg()
    
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd

; #########################################################################################
; # Progress Bar
; #########################################################################################

;ProgressOn ( "Account Creation", "IA Tool Kit" )

$UserName = ("Tester")
$Password = ("password")

$progress = $progress + 10

GuiCtrlSetData($progressbar, $progress)

; #########################################################################################
; # List users on the computer that have profiles created
; #########################################################################################

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler
Local $objDomain = ObjGet("WinNT://" & @ComputerName & "" )
Dim $filter[2] = ["user"]
$objDomain.Filter = $filter

$FileList=_FileListToArray("C:\Documents and Settings\","*",2) ;;search this folder for any folders within
If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf

;$aaUser = ""
$listOfProfiles = ""
$y = 0

For $aUser In $objDomain
   
   For $x = 1 to $FileList[0]
        Switch $FileList[$x]
            Case $aUser.Name                                 ;; users to process
                $y = $y + 1
                $listOfProfiles = $listOfProfiles & @CR & $y & " : " & $aUser.Name
            Case Else                                       ;; ignore all other users

        EndSwitch
    
            $progress = $progress + 5
        ;ProgressSet ( $progress )
        ;GUICtrlSetData(-1, $progress)
            GuiCtrlSetData($progressbar, $progress)
            
    Next
   
   
Next


MsgBox(0+48+4096, "List of Users with Profiles!", $listOfProfiles)


;COM Error function
Func ComError()
    If IsObj($oMyError) Then
        $HexNumber = Hex($oMyError.number, 8)
        ConsoleWrite($oMyError.scriptline & '  $HexNumber = ' & $HexNumber & "Windescription is: " & $oMyError.description & "|" & $oMyError.windescription  & @lf);### Debug Console
        SetError($HexNumber)
    Else
        SetError(1)
    EndIf
    Return 0
EndFunc ;==>ComError

;ProgressSet ( $progress )
$progress = $progress + 10
GuiCtrlSetData($progressbar, $progress)

; #########################################################################################
; # Create Tester account
; #########################################################################################

    $strComputer = @ComputerName
    $colAccounts = ObjGet("WinNT://" & $strComputer & "")
    $objUser = $colAccounts.Create("user", $UserName)
    $objUser.SetPassword ($Password)
    $objUser.Put ("Fullname", "Tester")
    $objUser.Put ("Description", "Testing Account")
    $objUser.SetInfo

;ProgressSet ( 70 )
$progress = $progress + 5
GuiCtrlSetData($progressbar, $progress)

; ########################################################################################
; # Add IATester to Administrator and Auditors
; ########################################################################################

$objGroup = ObjGet("WinNT://" & $strComputer & "/Administrators")
$objGroup.Add("WinNT://"&$UserName)

$objGroup = ObjGet("WinNT://" & $strComputer & "/Auditors")
$objGroup.Add("WinNT://"& $UserName)

;ProgressSet ( 100 )
$progress = 100
GuiCtrlSetData($progressbar, $progress)

; ########################################################################################
; # Force logout
; ########################################################################################

;shutdown (0)

Share this post


Link to post
Share on other sites



That is how you instructed your script to do. Look at the message loop, until $msg <> $GUI_EVENT_CLOSE the progress bar never gets updated and only if the user close it the rest of the source is getting executed.

Share this post


Link to post
Share on other sites

That is how you instructed your script to do. Look at the message loop, until $msg <> $GUI_EVENT_CLOSE the progress bar never gets updated and only if the user close it the rest of the source is getting executed.

I see that but how do I set it to also update after certain events occur? Like creating a account

Share this post


Link to post
Share on other sites

This cries out for the GUI to be in Event Mode. Set GuiOnEventMode and set a GUI event for $GUI_EVENT_CLOSE. Then you can go on to the rest of the script without bothering to be in a message loop.

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

This cries out for the GUI to be in Event Mode. Set GuiOnEventMode and set a GUI event for $GUI_EVENT_CLOSE. Then you can go on to the rest of the script without bothering to be in a message loop.

:P

but will that allow me to set where the updating of the progress bar occurs?

Share this post


Link to post
Share on other sites

but will that allow me to set where the updating of the progress bar occurs?

I don't really understand the question. What does that have to do with what mode the GUI is in? You have the ControlID of the progressbar control, you can update it anywhere\anytime you want.

In fact, if you use ProgressOn(), you don't have to create your GUI or worry about the mode at all! Since your GUI has nothing but the progressbar and some text, why bother? Just use ProgressOn(), then ProgressSet() as required.

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I don't really understand the question. What does that have to do with what mode the GUI is in? You have the ControlID of the progressbar control, you can update it anywhere\anytime you want.

In fact, if you use ProgressOn(), you don't have to create your GUI or worry about the mode at all! Since your GUI has nothing but the progressbar and some text, why bother? Just use ProgressOn(), then ProgressSet() as required.

:P

Well the rest of the code was just making sure I had the code right before putting this into a GUI... I am trying to put the accounts in a text box within the GUI.

ControlID was probably what I was looking for.

I know it works with the ProgressOn().. thats what I was using before.

Thanks I will look into ControlID

Share this post


Link to post
Share on other sites

Well the rest of the code was just making sure I had the code right before putting this into a GUI... I am trying to put the accounts in a text box within the GUI.

ControlID was probably what I was looking for.

I know it works with the ProgressOn().. thats what I was using before.

Thanks I will look into ControlID

OK. You saved the ControlID in $progressbar when you created it. Now you can do ControlSetData($progressbar, $iNewProgress) anywhere in the script.

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

OK. You saved the ControlID in $progressbar when you created it. Now you can do ControlSetData($progressbar, $iNewProgress) anywhere in the script.

:P

Ok so I had commented out the line I needed to make it work.. lol... working now.. Thanks

Share this post


Link to post
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
Sign in to follow this  
Followers 0