jazzyjeff Posted August 7, 2010 Share Posted August 7, 2010 Hello, I am creating a program that allows the library staff at my school to reset the passwords of students. I have successfully created a utility with inputbox popups. What I would like to do though is create a GUI interface to perform this task. The problem I am having with my GUI is that the username (and probably the password) that I enter is not being picked up in my script. For example, if I enter a username of "testteacher", I receive a message box back saying "The user, , is not a student." It should have said "The user, testteacher, is not a student. I am having a hard time seeing what is wrong with my code. I have read through various examples and the help file and I think my code looks good. Obviously it's not, so I am hoping someone can see what I am missing: This is my program: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <AD.au3> Opt("TrayIconHide", 1) Global $username, $password, $chkPWChange, $pwValue _AD_Open() ;Check to make sure the user running the script has permissions to reset passwords. ;If _AD_IsMemberOf("PasswordReset", @UserName) Then ; MsgBox(0, "TCAPS Password Reset Utility", @UserName & ", you have been granted access to use this utility.",4) ;Else ; MsgBox(0, "Access Denied", "You do not have permission to use this utility.") ; Exit ;EndIf #Region ### START Koda GUI section ### Form=C:\Users\carrollje\Desktop\AutoIT Script\Active Directory\PasswordResetGUI.kxf $mainForm = GUICreate("TCAPS Student Password Reset Utility", 447, 75, -1, -1) GUISetIcon("D:\Icons\TCAPS.ico") GUISetFont(10, 400, 0, "MS Sans Serif") GUISetBkColor(0xE3E3E3) $username = GUICtrlCreateInput("", 80, 8, 121, 24) $password = GUICtrlCreateInput("", 80, 40, 121, 24, $ES_PASSWORD,$ES_AUTOHSCROLL) $chkPWChange = GUICtrlCreateCheckbox("Prompt user to change password", 216, 8, 217, 17, BitOR($BS_CHECKBOX,$BS_AUTOCHECKBOX,$BS_RIGHTBUTTON)) $btnPWReset = GUICtrlCreateButton("Reset user password", 216, 40, 219, 25, $WS_GROUP) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $lblUsername = GUICtrlCreateLabel("Username", 8, 8, 67, 20, $WS_TABSTOP) $lblPassword = GUICtrlCreateLabel("Password", 8, 40, 64, 20, $WS_TABSTOP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ;Read data that has been inputted from the user $vUsername = GUICtrlRead($username) $vPassword = GUICtrlRead($password) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnPWReset _pwChange() If _AD_IsMemberOf("EL_Students", $vUsername) Or _AD_IsMemberOf("Sec_Students", $vUsername) Then _pwReset() Else MsgBox(0, "Access Denied", "You are trying to change the password of " & $vUsername & " who is not a student.") EndIf EndSwitch WEnd Func _pwChange() If BitAND(GUICtrlRead($chkPWChange), $GUI_CHECKED) = $GUI_CHECKED Then $pwValue = 1 Else $pwValue = 0 EndIf EndFunc ;==>_pwReset _AD_Close() Func _pwReset() _AD_SetPassword($vUsername, $vPassword, $pwValue) MsgBox(0, "Successful", "The password change for " & $vUsername & " has been successful.") EndFunc Any help on this is much appreciated. Thanks, Jeff Link to comment Share on other sites More sharing options...
smashly Posted August 7, 2010 Share Posted August 7, 2010 Hi, Move the GUICtrlRead() to where the button is pressedexpandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <AD.au3> Opt("TrayIconHide", 1) Global $username, $password, $chkPWChange, $pwValue _AD_Open() ;Check to make sure the user running the script has permissions to reset passwords. ;If _AD_IsMemberOf("PasswordReset", @UserName) Then ; MsgBox(0, "TCAPS Password Reset Utility", @UserName & ", you have been granted access to use this utility.",4) ;Else ; MsgBox(0, "Access Denied", "You do not have permission to use this utility.") ; Exit ;EndIf #Region ### START Koda GUI section ### Form=C:\Users\carrollje\Desktop\AutoIT Script\Active Directory\PasswordResetGUI.kxf $mainForm = GUICreate("TCAPS Student Password Reset Utility", 447, 75, -1, -1) GUISetIcon("D:\Icons\TCAPS.ico") GUISetFont(10, 400, 0, "MS Sans Serif") GUISetBkColor(0xE3E3E3) $username = GUICtrlCreateInput("", 80, 8, 121, 24) $password = GUICtrlCreateInput("", 80, 40, 121, 24, $ES_PASSWORD,$ES_AUTOHSCROLL) $chkPWChange = GUICtrlCreateCheckbox("Prompt user to change password", 216, 8, 217, 17, BitOR($BS_CHECKBOX,$BS_AUTOCHECKBOX,$BS_RIGHTBUTTON)) $btnPWReset = GUICtrlCreateButton("Reset user password", 216, 40, 219, 25, $WS_GROUP) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $lblUsername = GUICtrlCreateLabel("Username", 8, 8, 67, 20, $WS_TABSTOP) $lblPassword = GUICtrlCreateLabel("Password", 8, 40, 64, 20, $WS_TABSTOP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnPWReset ;Read data that has been inputted from the user $vUsername = GUICtrlRead($username) $vPassword = GUICtrlRead($password) _pwChange() If _AD_IsMemberOf("EL_Students", $vUsername) Or _AD_IsMemberOf("Sec_Students", $vUsername) Then _pwReset() Else MsgBox(0, "Access Denied", "You are trying to change the password of " & $vUsername & " who is not a student.") EndIf EndSwitch WEnd Func _pwChange() If BitAND(GUICtrlRead($chkPWChange), $GUI_CHECKED) = $GUI_CHECKED Then $pwValue = 1 Else $pwValue = 0 EndIf EndFunc ;==>_pwReset _AD_Close() Func _pwReset() _AD_SetPassword($vUsername, $vPassword, $pwValue) MsgBox(0, "Successful", "The password change for " & $vUsername & " has been successful.") EndFunc Cheers Link to comment Share on other sites More sharing options...
ALTIN Posted August 7, 2010 Share Posted August 7, 2010 Ahh smashly you were quicker then me! That's it Jeff, back to work now Link to comment Share on other sites More sharing options...
jazzyjeff Posted August 7, 2010 Author Share Posted August 7, 2010 Wow, it was as simple as that! Thanks guys. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now