Jump to content

wait for user input before continuing


Recommended Posts

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!

#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

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

You 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

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!

#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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...