Sign in to follow this  
Followers 0
Agent Orange

Progress Bar UDF question

7 posts in this topic

#1 ·  Posted (edited)

This script from RazerM looks great....http://www.autoitscript.com/forum/index.ph...=25588&st=0

I've added to my app that changes password in Active Directory. I'm wondering how to make the timing of the progress match the time it takes to change to pswd. Right now I can adjust the sleep time on it...but that isn't very acurate from PC to PC. For example, I can set the sleep so it works on one PC but if I run it on another it might get to 100% on the progress bar and still wait another 5 or 10 seconds before the final windows pops up saying the password was successfully change or not.

How can I make that wait time dynamic? Does that make sense?

Thanks

Edited by Agent Orange

Share this post


Link to post
Share on other sites



Your real problem is trying to figure out how long a command takes to complete.

You will have to be abled to get some sort of progress from the command you use to change the password. Otherwise, there's really no telling how long a command will take.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I agree and realize that. I may not have worded it correctly to begin with. The progress bar is giving info on the time it takes to call a user account from Active Directory change a password, or not change a password, in Active Directory using the command shown below.

The issue is that I'm finding this task can take longer on some PC than others.

Here is a snippit of code:

;there is of course more code above this
        Case $msg = $ChangeButton
    ;ProgressOn("Changing Password", "User:  " & GUICtrlRead($UserString), "0 percent",380,400)
    $prog = _ProgressOn($progress, $main, $sub, "Changing Password", "This is the sub-text", 175,317)
    For $i = 1 To 100
     _ProgressSet($prog, $i, "Processing: " & $i & "%")
     Sleep(500)
     Next
    $UserObj = ObjGet("WinNT://" & $DomainString & "/" & GUICtrlRead($UserString))
        _changepswd()
        _ProgressOff($prog)
 EndSelect

Func _changepswd()

If Not @error Then
$UserObj.ChangePassword(GUICtrlRead($currentpassword), GUICtrlRead($newpassword))
$UserObj.SetInfo
EndIf
Msgbox(0,"Update","Password Change Was Successful")
DriveMapDel("\\server\share")
Exit(0)
EndFunc

Anyway this can be done?

Edited by Agent Orange

Share this post


Link to post
Share on other sites

In a similar situation where I had a number of discrete functions that would be called multiple times each, and each one taking unknown lengths of time to complete, I made a fake once through the whole program to count the number of function calls, and then updated my progress bar according to what number of functions it had completed.

So if you can do a once through to count to total number of pcs, you could then update as a percentage of pcs done.

Share this post


Link to post
Share on other sites

Thanks nikink....can you give me an example based on the scripted snippet I posted?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks nikink....can you give me an example based on the scripted snippet I posted?

Well, I can give it a go B-)

#include <Date.au3>
Global $TallyOrDo = "Tally" ; sets whether or not the Script should tally the function calls or actually execute them 
Global $FunctionCount = 0 ; initialise the tally
Global $DoneFunctions = 0 ; Everytime a Function is called upon to execute, it should increment $DoneFunctions
Global $StartTime = _NowCalc()

Func _MyFunction1()
If $TallyOrDo= "Tally" Then ; increment the function tally for use with the Progressbar
        $FunctionCount = $FunctionCount + 1
Else ; Execute the function
; Function code goes here of course
_ShowProgress("My message to the viewer...")
EndIf
EndFunc

Func _MyFunction2()
If $TallyOrDo= "Tally" Then ; increment the function tally for use with the Progressbar
        $FunctionCount = $FunctionCount + 1
Else ; Execute the function
; Function code goes here of course
_ShowProgress("My message to the viewer...")
EndIf
EndFunc

Func _MyScript()
_MyFunction1()
_MyFunction2()
EndFunc

Func _ShowProgress($msg)
    ; Requires Global Parameters: StartTime, CompletedFunctionCalls and FunctionCount
    
    Local $RunTimeSeconds = 0
    Local $RunTimeMinutes = 0
    Local $RunTimeHours = 0
    
    $DoneFunctions = $DoneFunctions + 1
    $i = Int(($DoneFunctions / $FunctionCount) * 100)
    
    $RunTimeSeconds =  _DateDiff("s", $StartTime, _NowCalc())
    
    If ($RunTimeSeconds > 59) Then
        While $RunTimeSeconds > 59
            $RunTimeSeconds = $RunTimeSeconds - 60
            $RunTimeMinutes = $RunTimeMinutes + 1
            If $RunTimeMinutes > 59 Then
                $RunTimeMinutes = $RunTimeMinutes - 60
                $RunTimeHours = $RunTimeHours + 1
            EndIf
        WEnd
    EndIf
    
    ProgressSet( $i, "Time is now " & _NowTime() & ". Elapsed time: " & $RunTimeHours & "h:" & $RunTimeMinutes & "m:" & $RunTimeSeconds & "s. " & @LF _
                & $i & " percent complete. Please be patient..." & @LF _
                & $msg)

EndFunc   ;==>_ShowProgress

;;;; Main Program here ;;;;
ProgressOn("My Script is running!", "Script started at " & _NowTime(), "0 percent", -1, -1, 16)

For $i = 1 to 2 ; Ensures the script will run all the functions twice. 
    ; First time will Tally them, second time will Do them. Important for calculating ProgressBar Percentage complete.
_MyScript()
$TallyOrDo = "Do"
Next

ProgressSet(100 , "Script completed at " & _NowTime(), "Thankyou for your patience...")
sleep(1000)
ProgressOff()
Exit

Something like that anyway.

Edited by nikink

Share this post


Link to post
Share on other sites

Ahhh, I see what you'd talking about now. Thanks...I'll let you know if it works as hoped.

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