Jump to content

Need a little help for my macro


effer
 Share

Recommended Posts

Hi

I've created a macro with AutoIt 3 which types in your username and password for the intranet on my work.

My work has 18 different servers which the intranet is located on, and i've noticed that the macro not always works because of slightly different setups on the servers.

My macro works like this:

- check if the name of the intranet login window is active

- When it is active, enter username and password

The problem is that the title of the login windows differs on some of the servers..

My macro looks like this (the important part):

$user = InputBox("BMnet Login", "enter username\")
$pass = InputBox("BMnet Login", "enter password","","*")

While(1)

        WinWaitActive("Opret forbindelse til BMKC01")
        WinActivate("Opret forbindelse til BMKC01")
        Send($user)
        Send("{TAB}")
        Send($kode)
        Send("{ENTER}")

WEnd

My question is:

How do i make my while loop so I can check for more than one window name?

Hope you can figure it out, then I will be very happy :P

/Effer

Link to comment
Share on other sites

i cant find a solution but i know you are a dansker

Busted ! :P

I've just noticed an error in my script (because i tried to translate it into english before getting help, and I missed a translation):

The script should look like this:

$user = InputBox("BMnet Login", "enter username\")
$pass = InputBox("BMnet Login", "enter password","","*")

While(1)

        WinWaitActive("Opret forbindelse til BMKC01")
        WinActivate("Opret forbindelse til BMKC01")
        Send($user)
        Send("{TAB}")
        Send($pass)
        Send("{ENTER}")

WEnd
Link to comment
Share on other sites

is there any part in the windowtitle that stays the same

this part is not supposed to be in any other wintitle

Opt("WinTitleMatchMode", 2)
if winexists("forbindelse", "") then
winactivate("forbindelse", "")
send ($user&"{tab}"&$kode&"{enter}")
endif

hope this helps you

Link to comment
Share on other sites

Unless all the windows are identical except how they behave (UGG!), you might try something like this:

$user = InputBox("BMnet Login", "enter username\")
$pass = InputBox("BMnet Login", "enter password","","*")

While(1)
        If WinExists ("Opret forbindelse til BMKC01") then
                WinActivate("Opret forbindelse til BMKC01")
                Send($user)
                Send("{TAB}")
                Send($kode)
                Send("{ENTER}")
        ElseIf WinExists ( "Second Window Title", "Second Window Text" )
                WinActivate ( "Second Window Title", "Second Window Text" )
                Send($user)
                Send("{TAB}{TAB}")
                Send($kode)
                Send("{ENTER}")
        ElseIf WinExists ( "Third Window Title", "Third Window Text" )
                WinActivate ( "Third Window Title", "Third Window Text" )
                Send($user)
                Send("{TAB}{TAB}{TAB}")
                Send($kode)
                Send("{ENTER}")
        Endif
WEnd
Link to comment
Share on other sites

to update jerryd's idea

$user = InputBox("BMnet Login", "enter username\")
$pass = InputBox("BMnet Login", "enter password","","*")

While(1)
$a = WinExists ("Opret forbindelse til BMKC01") then
$b = WinExists ( "Second Window Title", "Second Window Text" )
$c = WinExists ( "Third Window Title", "Third Window Text" )
if $a = 1 or $b = 1 or $c = 1 then
select
case $a = 1             
WinActivate ( $a)
send ($user&"{tab}"&$kode&"{enter}")
case $b = 1
winactivate ($b)
send ($user&"{tab}"&$kode&"{enter}")
case $c = 1
winactivate ($c)
send ($user&"{tab}"&$kode&"{enter}")
endselect
Endif
WEnd

to make it a bit cleaner

$user = InputBox("BMnet Login", "enter username\")
$pass = InputBox("BMnet Login", "enter password","","*")

While(1)
$a = WinExists ("Opret forbindelse til BMKC01") then
$b = WinExists ( "Second Window Title", "Second Window Text" )
$c = WinExists ( "Third Window Title", "Third Window Text" )
select
case $a = 1             
typeme($a)
case $b = 1
typeme($b)
case $c = 1
typeme($c)
endselect
WEnd

func typeme($window)
winactivate ($window)
send ($user&"{tab}"&$kode&"{enter}")
endfunc

this should do the job (for title with not a part of similar string)

the other version is in my first post

Link to comment
Share on other sites

Unless all the windows are identical except how they behave (UGG!), you might try something like this:

$user = InputBox("BMnet Login", "enter username\")
$pass = InputBox("BMnet Login", "enter password","","*")

While(1)
        If WinExists ("Opret forbindelse til BMKC01") then
                WinActivate("Opret forbindelse til BMKC01")
                Send($user)
                Send("{TAB}")
                Send($kode)
                Send("{ENTER}")
        ElseIf WinExists ( "Second Window Title", "Second Window Text" )
                WinActivate ( "Second Window Title", "Second Window Text" )
                Send($user)
                Send("{TAB}{TAB}")
                Send($kode)
                Send("{ENTER}")
        ElseIf WinExists ( "Third Window Title", "Third Window Text" )
                WinActivate ( "Third Window Title", "Third Window Text" )
                Send($user)
                Send("{TAB}{TAB}{TAB}")
                Send($kode)
                Send("{ENTER}")
        Endif
WEnd

This is what i tried ealier too, but i couldn't get it to work.

But i've tried your code, and it works like a charm now :P , don't know what I did wrong.

So I guess I'm done... for now.

I might have some questions later, because I'm planing to add more functions.

But thanks for your help guys

Link to comment
Share on other sites

to update jerryd's idea

$user = InputBox("BMnet Login", "enter username\")
$pass = InputBox("BMnet Login", "enter password","","*")

While(1)
$a = WinExists ("Opret forbindelse til BMKC01") then
$b = WinExists ( "Second Window Title", "Second Window Text" )
$c = WinExists ( "Third Window Title", "Third Window Text" )
if $a = 1 or $b = 1 or $c = 1 then
select
case $a = 1             
WinActivate ( $a)
send ($user&"{tab}"&$kode&"{enter}")
case $b = 1
winactivate ($b)
send ($user&"{tab}"&$kode&"{enter}")
case $c = 1
winactivate ($c)
send ($user&"{tab}"&$kode&"{enter}")
endselect
Endif
WEnd

to make it a bit cleaner

$user = InputBox("BMnet Login", "enter username\")
$pass = InputBox("BMnet Login", "enter password","","*")

While(1)
$a = WinExists ("Opret forbindelse til BMKC01") then
$b = WinExists ( "Second Window Title", "Second Window Text" )
$c = WinExists ( "Third Window Title", "Third Window Text" )
select
case $a = 1             
typeme($a)
case $b = 1
typeme($b)
case $c = 1
typeme($c)
endselect
WEnd

func typeme($window)
winactivate ($window)
send ($user&"{tab}"&$kode&"{enter}")
endfunc

this should do the job (for title with not a part of similar string)

the other version is in my first post

I'll try your code later on too. The simpler, the better :P

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...