gcue Posted July 18, 2012 Share Posted July 18, 2012 hello world i am trying to authenticate to the network before running FUNC1. i tried putting in a while loop but then the login window OK or cancel buttons do not work any ideas? thanks in advance! expandcollapse popup#include <Constants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> #include <GuiButton.au3> Opt("GUIOnEventMode", 1) Global $ad_login_child, $ad_username_input, $ad_password_input, $ad_login_successful = False Global $msg_error = 262160 GUICreate("MAIN GUI", 200, 200) GUICtrlCreateButton("RUN", 20, 20) GUICtrlSetOnEvent(-1, "FUNC1") GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState() While 1 Sleep(10) WEnd Func FUNC1() If $ad_login_successful = False Then Network_Login_Prompt() while WinExists("Network Login") if $ad_login_successful=True then ExitLoop WEnd EndIf GUICreate("FUNC 1", 100, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState() EndFunc ;==>RUN_FUNC1 Func Network_Login_Prompt() $ad_login_child = GUICreate("Network Login", 265, 90, -1, -1, $WS_EX_MDICHILD, $WS_EX_TOPMOST) $ad_username_input = GUICtrlCreateInput(@UserName, 5, 5, 200, 20) $ad_password_input = GUICtrlCreateInput("", 5, 30, 200, 20, $ES_PASSWORD) GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlCreateButton("OK", 210, 5, 40, 20, $BS_DEFPUSHBUTTON) GUICtrlSetOnEvent(-1, "Network_Login") GUICtrlCreateButton("Cancel", 210, 30, 40, 20) GUICtrlSetOnEvent(-1, "DEL_ad_login_child") GUISetState() EndFunc ;==>Network_Login_Prompt Func DEL_ad_login_child() GUIDelete($ad_login_child) EndFunc ;==>DEL_ad_login_child Func Network_Login() $ad_username = GUICtrlRead($ad_username_input) $ad_password = GUICtrlRead($ad_password_input) If $ad_username = "" Or $ad_password = "" Then MsgBox($msg_error, @ScriptName, "Please type in Username and Password first.") Return EndIf $valid = _ValidUserPass($ad_username, "DOMAIN", $ad_password) If $valid = True Then $ad_login_successful = True DEL_ad_login_child() Else GUICtrlSetData($ad_password_input, "") GUICtrlSetState($ad_password_input, $GUI_FOCUS) MsgBox($msg_error, @ScriptName, "Password was typed incorrectly - please try again.") Return EndIf EndFunc ;==>Network_Login Func _ValidUserPass($username, $computer, $password) Local $valid = True RunAs($username, $computer, $password, 0, @ComSpec & " /c echo test", @SystemDir, @SW_HIDE) If @error Then $valid = False Return $valid EndFunc ;==>_ValidUserPass Func _Exit() Exit EndFunc ;==>_Exit Link to comment Share on other sites More sharing options...
JohnOne Posted July 18, 2012 Share Posted July 18, 2012 i am trying to authenticate to the network before running FUNC1. i tried putting in a while loop but then the login window OK or cancel buttons do not workYou could simply disable the run button until authentication. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
gcue Posted July 18, 2012 Author Share Posted July 18, 2012 hmm.. but it isnt till you click the button that you get prompted for authentication. Link to comment Share on other sites More sharing options...
JohnOne Posted July 18, 2012 Share Posted July 18, 2012 So create another button or something. You cannot wait until after a task before using a function that completes that same task, or am I missing something? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
gcue Posted July 18, 2012 Author Share Posted July 18, 2012 there should be a way - i thought i remember seeing once (with a while loop) Link to comment Share on other sites More sharing options...
JohnOne Posted July 18, 2012 Share Posted July 18, 2012 1. FUNC1 runs other functions that login to your network. is that right? 2. You do not want to run FUNC1 until you are logged into your network. is that right? 3. WTFLOL AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
gcue Posted July 18, 2012 Author Share Posted July 18, 2012 ok i figured out a way i pass the function name along the way (this way i can use the same function to authenticate to other functions that need ad authentication) thanks for your help! expandcollapse popup#include <Constants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> #include <GuiButton.au3> #include <OnEventFunc.au3> Opt("GUIOnEventMode", 1) Global $ad_login_child, $ad_username_input, $ad_password_input, $ad_login_successful = False Global $msg_error = 262160 GUICreate("MAIN GUI", 200, 200) GUICtrlCreateButton("RUN", 20, 20) GUICtrlSetOnEvent(-1, "FUNC1") GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState() While 1 Sleep(10) WEnd Func FUNC1() If $ad_login_successful = False Then Network_Login_Prompt("FUNC2") Else FUNC2() EndIf EndFunc ;==>RUN_FUNC1 Func FUNC2() GUICreate("FUNC 2", 100, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState() EndFunc Func Network_Login_Prompt($function) $ad_login_child = GUICreate("Network Login", 265, 90, -1, -1, $WS_EX_MDICHILD, $WS_EX_TOPMOST) $ad_username_input = GUICtrlCreateInput(@UserName, 5, 5, 200, 20) $ad_password_input = GUICtrlCreateInput("", 5, 30, 200, 20, $ES_PASSWORD) GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlCreateButton("OK", 210, 5, 40, 20, $BS_DEFPUSHBUTTON) ;~ GUICtrlSetOnEvent(-1, "Network_Login") SetOnEvent(-1, "Network_Login", 1, $ParamByVal, $function) GUICtrlCreateButton("Cancel", 210, 30, 40, 20) GUICtrlSetOnEvent(-1, "DEL_ad_login_child") GUISetState() EndFunc ;==>Network_Login_Prompt Func DEL_ad_login_child() GUIDelete($ad_login_child) EndFunc ;==>DEL_ad_login_child Func Network_Login($function) $ad_username = GUICtrlRead($ad_username_input) $ad_password = GUICtrlRead($ad_password_input) If $ad_username = "" Or $ad_password = "" Then MsgBox($msg_error, @ScriptName, "Please type in Username and Password first.") Return EndIf $valid = _ValidUserPass($ad_username, "DOMAIN", $ad_password) If $valid = True Then $ad_login_successful = True DEL_ad_login_child() Else GUICtrlSetData($ad_password_input, "") GUICtrlSetState($ad_password_input, $GUI_FOCUS) MsgBox($msg_error, @ScriptName, "Password was typed incorrectly - please try again.") Return EndIf Call($function) EndFunc ;==>Network_Login Func _ValidUserPass($username, $computer, $password) Local $valid = True RunAs($username, $computer, $password, 0, @ComSpec & " /c echo test", @SystemDir, @SW_HIDE) If @error Then $valid = False Return $valid EndFunc ;==>_ValidUserPass Func _Exit() Exit EndFunc ;==>_Exit 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