Sign in to follow this  
Followers 0
anyday

login/password prompt

18 posts in this topic

i have a program for work that everytime i open it up, which is like 20 - 30 times a day, it ask's me for my login and password.

I have no problems creating script that will enter this information for me, my question is whats the best way to have to loop where it is always looking for the window? ide like the script to always run maybe as a service and always be on the lookout for this window to pop up asking for login info.

$user = "username"
$pass = "pass"
WinWaitActive("Login", "Reset Password")
ControlSend("Login", "Reset Password", "ThunderRT6TextBox4", $user)
ControlSend("Login", "Reset Password", "ThunderRT6TextBox3", $pass)
Sleep (20000)
ControlClick("Login", "Reset Password", "ThunderRT6CommandButton3")

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

How 'bout this?

$user = "username"
$pass = "pass"

Login($user,$pass)

Func Login($user,$pass)
    Do
        Sleep(2000)
    Until WinExists("Login", "Reset Password")
    ControlSend("Login", "Reset Password", "ThunderRT6TextBox4", $user)
    ControlSend("Login", "Reset Password", "ThunderRT6TextBox3", $pass)
    Sleep (20000)
    ControlClick("Login", "Reset Password", "ThunderRT6CommandButton3")
    Login($user,$pass)
EndFunc
Edited by spudw2k

Share this post


Link to post
Share on other sites

seems to be working good, thanks alot

Share this post


Link to post
Share on other sites

only drawback i see is that after everytime the script executes the login process, the mem usage increases, so if it is run 30 , 40 times a day 7 days a week that could become a problem, any way of having the script terminate and restart itself after every login?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

$user = "user"
$pass = "pass"

Login($user,$pass)

Func Login($user,$pass)
    Do
        Sleep(2000)
    Until WinExists("Logon", "Reset Password")
    ControlSend("Logon", "Reset Password", "ThunderRT6TextBox4", $user)
    ControlSend("Logon", "Reset Password", "ThunderRT6TextBox3", $pass)
    Sleep (2000)
    ControlClick("Logon", "Reset Password", "ThunderRT6CommandButton3")
    Run ("login.exe", "")
    Exit
EndFunc

prob not the best way to do it but it works, any suggestions would be great

also, there are more than one programs that asks for this same login and pass, there are different prompts any ideas? if statements maybe?

Edited by anyday

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Is this any better? Otherwise, the Run method you chose should work too.

Global $user = "username"
Global $pass = "pass"

AdlibEnable("Login",500)
HotKeySet("^!x","Quit")   ;Ctrl+Alt+x to Quit

While 1
    Sleep(1000)
WEnd

Func Login()
    If WinExists("Login", "Reset Password") Then 
        ControlSend("Login", "Reset Password", "ThunderRT6TextBox4", $user)
        ControlSend("Login", "Reset Password", "ThunderRT6TextBox3", $pass)
        Sleep (20000)
        ControlClick("Login", "Reset Password", "ThunderRT6CommandButton3")
    EndIf
EndFunc

Func Quit()
    Exit
EndFunc
Edited by spudw2k

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

It might help if you understood the Sleep() command better. Sleep(1000) pauses the script for 1 second and Sleep(2000) pauses for 2 seconds. Is it necessary for the script to look for the login dialog every few seconds??? I wouldn't think so, but you're the only one that can answer that question. If it were me, I'd try and figure out what causes the login to pop-up. Does it happen every 5 minutes? Is it tied to keyboard/mouse inactivity like a screen saver???

Once you've figured out the trigger for the login you're trying to get around, then set Sleep() to a more CPU friendly interval. For example, if you know the login pops up every 10 minutes then you can have your script look for the window every 60 seconds (60 x 1000 = 60,000) so you'd use Sleep(60000). Things can get complicated in a hurry, but sometimes it best to keep it simple.

Another thing to understand is the AdlibEnable(). Spudw2k suggests AdlibEnable("Login",500). However the 500 is milliseconds and would cause the function/script to run every half second. If Sleep(1000) runs every second and AdibEnable("Login",500) runs twice every second ... imagine how this will slow down your CPU.

Not that I don't know much about this stuff, because I really don't, but I would have tweaked your original code like this:

$user = "username"
$pass = "pass"

While 1
     Sleep(60000) ;pauses script 60 seconds before checking for Login
     WinWaitActive("Login", "Reset Password")
     ControlSend("Login", "Reset Password", "ThunderRT6TextBox4", $user)
     ControlSend("Login", "Reset Password", "ThunderRT6TextBox3", $pass)
     Sleep (20000)
     ControlClick("Login", "Reset Password", "ThunderRT6CommandButton3")
Wend

Hope this helps and good luck.

Edited by ssubirias3

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

ok so here's what i got now, im prob doing this all wrong but, here's my problem, i need this script to look out for multiple prompts that use the same password. here's what i have which seems to work sometimes. i just need the script to sit and wait for any of 3 or 4 different prompts any ideas the best way?

$user = "login"
$pass = "pass"
$anagent = "Connect to secure.website.com"
$fflogin = "fflogin"
$ffpass = "ffpass"
Sleep (3000)
    If WinExists("SAGE Logon", "Reset Password") Then
        WinActivate("SAGE Logon", "Reset Password")
            WinWaitActive("SAGE Logon", "Reset Password")
        ControlFocus("SAGE Logon", "Reset Password", "ThunderRT6TextBox4")
            Sleep(1000)
                ControlSend("SAGE Logon", "Reset Password", "ThunderRT6TextBox4", $user)
        ControlFocus("SAGE Logon", "Reset Password", "ThunderRT6TextBox3")
            Sleep(1000)
                ControlSend("SAGE Logon", "Reset Password", "ThunderRT6TextBox3", $pass)
        ControlClick("SAGE Logon", "Reset Password", "ThunderRT6CommandButton3")
    ElseIf WinExists("Login", "Reset Password") Then
        WinActivate("Login", "Reset Password")
            WinWaitActive("Login", "Reset Password")
        ControlFocus("Login", "Reset Password", "ThunderRT6TextBox1")
    ;Sleep(1000)
                Send ($user&"{enter}");ControlSend("Login", "Reset Password", "ThunderRT6TextBox1", $user)
    ;Sleep(500)
        ControlFocus("Login", "Reset Password", "ThunderRT6TextBox2")
    ;Sleep(500)
                Send ($pass);ControlSend("Login", "Reset Password", "ThunderRT6TextBox1", $pass)
    ;Sleep(1000)
        ControlFocus("Login", "Reset Password", "ThunderRT6CommandButton3")
        Send("{ENTER}")
;ControlClick("Login", "Reset Password", "ThunderRT6CommandButton3")
    ElseIf WinExists($anagent, "") Then
            WinWaitActive($anagent, "")
        ControlFocus($anagent, "", "Edit2")
            ControlSend($anagent, "", "Edit2", $user)
        ControlFocus($anagent, "", "Edit3")
            ControlSend($anagent, "", "Edit3", $pass)
        ControlClick($anagent, "", "Button2")
EndIf
    If WinExists("Choose a digital certificate", "") Then
            WinWaitActive("Choose a digital certificate", "")
        ControlClick("Choose a digital certificate", "", "Button2")
    ElseIf WinExists("Connect to infocenter1.website.com", "") Then
            WinWaitActive("Connect to infocenter1.website.com", "")
        ControlFocus("Connect to infocenter1.website.com", "", "Edit2")
            ControlSend("Connect to infocenter1.website.com", "", "Edit2", $fflogin)
        ControlFocus("Connect to infocenter1.website.com", "", "Edit3")
            ControlSend("Connect to infocenter1.website.com", "", "Edit3", $ffpass)
        ControlClick("Connect to infocenter1.website.com", "", "Button2")
    EndIf
run("logon3.exe", "")
Exit
Edited by anyday

Share this post


Link to post
Share on other sites

Global $user = "user"
Global $pass = "pass"

AdlibEnable("Login", 500)
AdLibEnable("TransLogin", 500)
HotKeySet("^!x", "Quit"); Ctrl+Alt+X

While 1
    Sleep (1000)
WEnd

Func Login()
    If WinExists("Server Based Rating Logon", "Reset Password") Then
        ControlSend("Server Based", "Reset Password", "ThunderRT6TextBox4", $user)
        ControlSend("Server Based", "Reset Password", "ThunderRT6TextBox3", $pass)
        ControlFocus("Server Based", "Reset Password", "ThunderRT6CommandButton3")
        ControlClick("Server Based", "Reset Password", "ThunderRT6CommandButton3")
    EndIf
EndFunc

Func TransLogin()
    If WinExists("Login", "Reset Password") Then
        ControlFocus("Login", "Reset Password", "ThunderRT6TextBox1")
        ControlSend("Login", "Reset Password", "ThunderRT6TextBox1", $user)
        ControlFocus("Login", "Reset Password", "ThunderRT6TextBox2")
        ControlSend("Login", "Reset Password", "ThunderRT6TextBox2", $pass)
        ControlFocus("Login", "Reset Password", "ThunderRT6CommandButton3")
        ControlClick("Login", "Reset Password", "ThunderRT6CommandButton3")
        WinWaitClose("Login", "Reset Password")
    EndIf
EndFunc


Func Quit()
    Exit
EndFunc

Got a question about the code above, the send function works fine, the TransLogin() function. The Login() function worked fine until i added the TransLogin() function. now the login() function does not work at all any ideas? my idea of how this code would run is ever 500ms it checks the first function then 500ms checks the 2nd and just keeps repeating?

Share this post


Link to post
Share on other sites

been going crazy for 2 days now, trying to figure out how to make a script that watchs for up to 4 or 5 different logon prompts with no luck anyone with any fresh ideas?

Share this post


Link to post
Share on other sites

I would use an array for it:

Global $user = "user"
Global $pass = "pass"

Dim $LogonArray[2][3]
    $LogonArray[0][0] = "Server Based Rating Logon"     ; Window Title
    $LogonArray[0][1] = "Reset Password"                ; Window Text
    $LogonArray[0][2] = "Login"                         ; Function to call for this window
    
    $LogonArray[1][0] = "Login"                         ; Window Title
    $LogonArray[1][1] = "Reset Password"                ; Window Text
    $LogonArray[0][2] = "TransLogin"                    ; Function to call for this window

HotKeySet("^!x", "Quit"); Ctrl+Alt+X

While 1
    For $i = 0 To UBound($LogonArray)-1
        If WinExists($LogonArray[$i][0], $LogonArray[$i][1]) Then
            Call($LogonArray[$i][2])
        EndIf
    Next
    Sleep (1000)
WEnd

Func Login()
    ControlSend("Server Based", "Reset Password", "ThunderRT6TextBox4", $user)
    ControlSend("Server Based", "Reset Password", "ThunderRT6TextBox3", $pass)
    ControlFocus("Server Based", "Reset Password", "ThunderRT6CommandButton3")
    ControlClick("Server Based", "Reset Password", "ThunderRT6CommandButton3")
EndFunc

Func TransLogin()
    ControlFocus("Login", "Reset Password", "ThunderRT6TextBox1")
    ControlSend("Login", "Reset Password", "ThunderRT6TextBox1", $user)
    ControlFocus("Login", "Reset Password", "ThunderRT6TextBox2")
    ControlSend("Login", "Reset Password", "ThunderRT6TextBox2", $pass)
    ControlFocus("Login", "Reset Password", "ThunderRT6CommandButton3")
    ControlClick("Login", "Reset Password", "ThunderRT6CommandButton3")
    WinWaitClose("Login", "Reset Password")
EndFunc


Func Quit()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

thanks for the code and help, doesnt seem to work though, not sure what the prob is, the "Login" screen pops up and nothing happens

and whats really weird is if i change out $LogonArray[0][0] with "Login" it executes the TransLogin function.

Dim $LogonArray[2][3]
    $LogonArray[0][0] = "Login" ; Window Title
    $LogonArray[0][1] = "Reset Password"               ; Window Text
    $LogonArray[0][2] = "Login"   ; Function to call for this window
    
    $LogonArray[1][0] = "Login"   ; Window Title
    $LogonArray[1][1] = "Reset Password"               ; Window Text
    $LogonArray[0][2] = "TransLogin"                   ; Function to call for this window

HotKeySet("^!x", "Quit"); Ctrl+Alt+X

While 1
    For $i = 0 To UBound($LogonArray)-1
        If WinExists($LogonArray[$i][0], $LogonArray[$i][1]) Then
            Call($LogonArray[$i][2])
        EndIf
    Next
    Sleep (1000)
WEnd

Func Login()
    ControlSend("Server Based", "Reset Password", "ThunderRT6TextBox4", $user)
    ControlSend("Server Based", "Reset Password", "ThunderRT6TextBox3", $pass)
    ControlFocus("Server Based", "Reset Password", "ThunderRT6CommandButton3")
    ControlClick("Server Based", "Reset Password", "ThunderRT6CommandButton3")
EndFunc

Func TransLogin()
    ControlFocus("Login", "Reset Password", "ThunderRT6TextBox1")
    ControlSend("Login", "Reset Password", "ThunderRT6TextBox1", $user)
    ControlFocus("Login", "Reset Password", "ThunderRT6TextBox2")
    ControlSend("Login", "Reset Password", "ThunderRT6TextBox2", $pass)
    ControlFocus("Login", "Reset Password", "ThunderRT6CommandButton3")
    ControlClick("Login", "Reset Password", "ThunderRT6CommandButton3")
    WinWaitClose("Login", "Reset Password")
EndFunc
Edited by anyday

Share this post


Link to post
Share on other sites

ahh that work's good, there was a typo in your post

Dim $LogonArray[2][3]
    $LogonArray[0][0] = "Server Based Rating Logon" ; Window Title
    $LogonArray[0][1] = "Reset Password"               ; Window Text
    $LogonArray[0][2] = "Login"   ; Function to call for this window
    
    $LogonArray[1][0] = "Login"   ; Window Title
    $LogonArray[1][1] = "Reset Password"               ; Window Text
    $LogonArray[0][2] = "TransLogin"                   ; Function to call for this window

$LogonArray[1][0] = "Login" ; Window Title

$LogonArray[1][1] = "Reset Password" ; Window Text

$LogonArray[0][2] = "TransLogin" ; Function to call for this window

it was calling the same function $LogonArray[0][2]

thanks alot for the help!

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Edit:

Oh, nice find. xD

Good it works. :)

Edited by FreeFry

Share this post


Link to post
Share on other sites

ok, next question, any way to make the script restart itself so mem usage does not get to high? i can do it by just an exit then a run of the exe but prob not the best way?

Share this post


Link to post
Share on other sites

I don't think is any need to restart it, it shouldn't use that much memory in any case..

Share this post


Link to post
Share on other sites

write an another script to restart it (Close the existing one and restart it). simple...

Share this post


Link to post
Share on other sites

And pointless.

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