Sign in to follow this  
Followers 0
darkleton

Problem with buttons resetting themselves

2 posts in this topic

I have a GUi that can read if a users account is disabled or not and then display an enable/disable button accordingly.

I've tested it and say the users account is enabled, i click disable, it disables the account, updates the display and the button then changes to 'enable'.

The problem is, if i move my mouse over the enable button it changes to disable and tries to disable the account again.

I thought that by making it refresh the displayinfo part it would update it all, but the buttons just aren't working.

This is the part of my script thats causing problems:

Func DisplayInfo()

$leftfqdn = ReadFQDNFromGUILeft()
$leftsam = _ADDNToSamAccountName ($leftfqdn)
$UserObj = ObjGet("LDAP://" & $leftfqdn)

GUICtrlCreateLabel ( ''& $leftsam, 750, 90, 100, 20)
GUICtrlCreateLabel (''& $UserObj.FirstName, 750, 145, 100, 20)   
GUICtrlCreateLabel (''& $UserObj.LastName, 750, 170, 100, 20)   
GUICtrlCreateLabel (''& $UserObj.FullName, 750, 200, 300, 20)   
GUICtrlCreateLabel (''& $UserObj.Description, 750, 230, 300, 20)  
GUICtrlCreateLabel (''& $UserObj.LoginScript, 750, 285, 200, 20)

$lastchange = $UserObj.PasswordLastChanged
$Date = StringMid($lastchange, 7, 2) & "/" & StringMid($lastchange, 5, 2) & "/" & StringMid($lastchange, 1, 4)
$Time = StringMid($lastchange, 9, 2) & ":" & StringMid($lastchange, 11, 2) ;& ":" & StringMid($lastchange, 13, 2)
GUICtrlCreateLabel ($Time & " - "& $Date, 750, 315, 150, 20)

$lastlogin = $UserObj.LastLogin
$Date = StringMid($lastlogin, 7, 2) & "/" & StringMid($lastlogin, 5, 2) & "/" & StringMid($lastlogin, 1, 4)
$Time = StringMid($lastlogin, 9, 2) & ":" & StringMid($lastlogin, 11, 2) ;& ":" & StringMid($lastlogin, 13, 2)
GUICtrlCreateLabel ($Time & " - "& $Date, 750, 355, 150, 20)

$btn_resetpass = GUICtrlCreateButton("Reset Users Password", 700, 500, 130, 20)
GUICtrlSetOnEvent($btn_resetpass, "ResetPass")


    If $UserObj.AccountDisabled = 0 Then
        GUICtrlCreateLabel ('No', 750, 385, 20, 15)
        GUICtrlSetBkColor(-1, 0x00ff00);Green
        $btn_disableacct = GUICtrlCreateButton("Disable Users Account", 700, 520, 130, 20)
        GUICtrlSetOnEvent($btn_disableacct, "DisableAcct")
    EndIf
    
    If $UserObj.AccountDisabled = -1 Then
        GUICtrlCreateLabel ('Yes', 750, 385, 20, 15)
        GUICtrlSetBkColor(-1, 0xEE0000);Red
        $btn_enableacct = GUICtrlCreateButton("Enable Users Account", 700, 520, 130, 20)
        GUICtrlSetOnEvent($btn_enableacct, "EnableAcct")
    EndIf

EndFunc 

Func DisableAcct()
    $leftfqdn = ReadFQDNFromGUILeft()
    $leftsam = _ADDNToSamAccountName ($leftfqdn)
    $UserObj = ObjGet("LDAP://" & $leftfqdn)
    $UserObj.AccountDisabled = -1
    $UserObj.SetInfo
    MsgBox(0, "", $leftsam & "'s account has been disabled", 2)
    DisplayInfo()
EndFunc 


Func EnableAcct()
    $leftfqdn = ReadFQDNFromGUILeft()
    $leftsam = _ADDNToSamAccountName ($leftfqdn)
    $UserObj = ObjGet("LDAP://" & $leftfqdn)
    $UserObj.AccountDisabled = 0
    $UserObj.SetInfo
    MsgBox(0, "", $leftsam & "'s account has been enabled", 2)
    DisplayInfo()
EndFunc 


Func ResetPass()
    $leftfqdn = ReadFQDNFromGUILeft()
    $leftsam = _ADDNToSamAccountName ($leftfqdn)
    $UserObj = ObjGet("LDAP://" & $leftfqdn)
    $UserObj.SetPassword ("p")
    MsgBox(0, "", $leftsam & "'s password has been reset to the letter P", 2)
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

As far i can see you are creating a new button every time. After 2 cycles you seems to have 4 buttons at the same place. Just check the CtrlID to be sure of that. Which button are you click on then ?

I have tried it and i don't see why you are creating a new button instead of changing the caption of the button. Look here:

#include <GUIConstants.au3>
GUICreate("Main")
$btn = GUICtrlCreateButton("Enabled",5,5,100,50)
GUISetState()
While 1
    $msg = GUIGetMsg()
    If $msg = $btn Then
        $state = GUICtrlRead($btn)
        MsgBox(0,"State",$state,1)
        If $state = "Enabled" Then
            GUICtrlSetData($btn,"Disabled")
        Else
            GUICtrlSetData($btn,"Enabled")
        EndIf
    EndIf
    if $msg = $GUI_EVENT_CLOSE Then
        ExitLoop
    EndIf
WEnd

So you are able to change the caption without creating new ones and without having to refresh the GUI.

Edited by Dschingis

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