Jump to content

Trying to write a script to react to different messages


Recommended Posts

I don't know where to start with this one, so I figured I'd ask.

I'm looking to write a simple script that will check the text in a message box, and depending on what the box says preform one of two actions. I've lurked enough to know how to write in the actions, but not to create the script to check the message box.

The box that comes up shows that the action was completed successfully or failed. The problem is that the title of the box and the text in it are different depending on if the action succeedes or fails.

I don't need this to be a loop, I only need it to run once.

Thanks for the help

sloppyjoe

Link to comment
Share on other sites

This piece of code might be helpful...Understand that there are no error loops {Else or ElseIf} in the example code.

This line $ChatBox = ControlGetText($CommunityPatch, "", 1731) reads the EditBox for an in-house IM application. You will need to use the AutoIT Window Info tool to discover the ControlID# for your software.

I read in the contents of an .ini file in order to gather Server Admins (SA) and Server Commands into an array and convert the array to a single dimension in order to use _ArrayDisplay() and _ArraySearch().

[sERVER_ADMIN]

JTGalore=SA

Ih8teU=SA

MMonroe=CA

[sERVER_COMMANDS]

%PMgr=Process Manager

%Update=AV definitions file update

%HotFix=HotFix & Quick-engineering check

I test the last line of the edit box looking for the combination of ":)" without quotes. I read it into an array...I test the UserName against the SA array and the command against the Cmd array--If all pass the test then the server will process the command.

#Include<Array.au3>
$ConfigFile = "ChatBox.ini"
$CommunityPatch = IniRead($ConfigFile, "COMMUNITY", "Patch", "")
$AuthCmd = ":>"
$Username = IniReadSection($ConfigFile, "SERVER_ADMIN")
$Commands = IniReadSection($ConfigFile, "SERVER_COMMANDS")
Dim $ChatBox_SA[20]
Dim $ChatBox_Cmd[10]
For $i = 1 To $Username[0][0]
    $ChatBox_SA[$i] = $Username[$i][0]
Next
For $i = 1 To $Commands[0][0]
    $ChatBox_Cmd[$i] = $Commands[$i][0]
Next
;_ArrayDisplay($CHatBox_SA, "Server Admins")
$ChatBox = ControlGetText($CommunityPatch, "", 1731)
$ChatBox1 = StringTrimRight(StringTrimLeft ($ChatBox, (StringInStr ($ChatBox, $AuthCmd,0,-1))-1),2)
$ChatBox2 = StringLen($ChatBox1)
$array = StringSplit($ChatBox1, ' ', 1)
;_ArrayDisplay($array, "What's the last line in the box")
;MsgBox(0,$ChatBox1, $ChatBox1 & " <> " & $ChatBox2)
IF $array[1] == $AuthCmd THEN
    $getSA = _ArraySearch($ChatBox_SA, $array[2])
    IF $array[2] = $ChatBox_SA[$getSA] Then
        $getCmd = _ArraySearch($ChatBox_Cmd, $array[3])
        IF $array[3] = $ChatBox_Cmd[$getCmd] Then
            _ArrayDisplay($array, "SA Command to execute goes here")
        EndIf
    EndIf
EndIf
Link to comment
Share on other sites

This piece of code might be helpful...Understand that there are no error loops {Else or ElseIf} in the example code.

This line $ChatBox = ControlGetText($CommunityPatch, "", 1731) reads the EditBox for an in-house IM application. You will need to use the AutoIT Window Info tool to discover the ControlID# for your software.

I read in the contents of an .ini file in order to gather Server Admins (SA) and Server Commands into an array and convert the array to a single dimension in order to use _ArrayDisplay() and _ArraySearch().

[sERVER_ADMIN]

JTGalore=SA

Ih8teU=SA

MMonroe=CA

[sERVER_COMMANDS]

%PMgr=Process Manager

%Update=AV definitions file update

%HotFix=HotFix & Quick-engineering check

I test the last line of the edit box looking for the combination of ":)" without quotes. I read it into an array...I test the UserName against the SA array and the command against the Cmd array--If all pass the test then the server will process the command.

#Include<Array.au3>
$ConfigFile = "ChatBox.ini"
$CommunityPatch = IniRead($ConfigFile, "COMMUNITY", "Patch", "")
$AuthCmd = ":>"
$Username = IniReadSection($ConfigFile, "SERVER_ADMIN")
$Commands = IniReadSection($ConfigFile, "SERVER_COMMANDS")
Dim $ChatBox_SA[20]
Dim $ChatBox_Cmd[10]
For $i = 1 To $Username[0][0]
    $ChatBox_SA[$i] = $Username[$i][0]
Next
For $i = 1 To $Commands[0][0]
    $ChatBox_Cmd[$i] = $Commands[$i][0]
Next
;_ArrayDisplay($CHatBox_SA, "Server Admins")
$ChatBox = ControlGetText($CommunityPatch, "", 1731)
$ChatBox1 = StringTrimRight(StringTrimLeft ($ChatBox, (StringInStr ($ChatBox, $AuthCmd,0,-1))-1),2)
$ChatBox2 = StringLen($ChatBox1)
$array = StringSplit($ChatBox1, ' ', 1)
;_ArrayDisplay($array, "What's the last line in the box")
;MsgBox(0,$ChatBox1, $ChatBox1 & " <> " & $ChatBox2)
IF $array[1] == $AuthCmd THEN
    $getSA = _ArraySearch($ChatBox_SA, $array[2])
    IF $array[2] = $ChatBox_SA[$getSA] Then
        $getCmd = _ArraySearch($ChatBox_Cmd, $array[3])
        IF $array[3] = $ChatBox_Cmd[$getCmd] Then
            _ArrayDisplay($array, "SA Command to execute goes here")
        EndIf
    EndIf
EndIf
Sorry, but I'm new to this and don't understand any of what you wrote.

Here's the info for the dialog boxes. The first one (if it appears) I just need autoit to send the enter command and run a program:

>>>>>>>>>>>> Window Details <<<<<<<<<<<<<

Title: Update SQL With NIC and Computer Name

Class: #32770

Size: X: 231 Y: 249 W: 344 H: 126

>>>>>>>>>>> Mouse Details <<<<<<<<<<<

Screen: X: 397 Y: 343

Cursor ID: 2

>>>>>>>>>>> Pixel Color Under Mouse <<<<<<<<<<<

RGB: Hex: 0xECE9D8 Dec: 15526360

>>>>>>>>>>> Control Under Mouse <<<<<<<<<<<

Size: X: 131 Y: 60 W: 75 H: 23

Control ID: 2

ClassNameNN: Button1

Text: OK

Style: 0x50030001

ExStyle: 0x00000004

>>>>>>>>>>> Status Bar Text <<<<<<<<<<<

>>>>>>>>>>> Visible Window Text <<<<<<<<<<<

OK

NIC Address and Computer Name updated Successfully.

>>>>>>>>>>> Hidden Window Text <<<<<<<<<<<

---------------------

These are what come up if the program fails:

>>>>>>>>>>>> Window Details <<<<<<<<<<<<<

Title: Get_MAC_And_ComputerName

Class: #32770

Size: X: 237 Y: 332 W: 555 H: 119

>>>>>>>>>>> Mouse Details <<<<<<<<<<<

Screen: X: 529 Y: 427

Cursor ID: 2

>>>>>>>>>>> Pixel Color Under Mouse <<<<<<<<<<<

RGB: Hex: 0xD4D0C8 Dec: 13947080

>>>>>>>>>>> Control Under Mouse <<<<<<<<<<<

Size: X: 237 Y: 60 W: 75 H: 23

Control ID: 2

ClassNameNN: Button1

Text: OK

Style: 0x50030001

ExStyle: 0x00000004

>>>>>>>>>>> Status Bar Text <<<<<<<<<<<

>>>>>>>>>>> Visible Window Text <<<<<<<<<<<

OK

Your NIC Card Address '0011439EBC9B' Was NOT found in the Database.

>>>>>>>>>>> Hidden Window Text <<<<<<<<<<<

----You click ok, then get this dialog box -----

>>>>>>>>>>>> Window Details <<<<<<<<<<<<<

Title: Update SQL With NIC and Computer Name

Class: #32770

Size: X: 344 Y: 332 W: 344 H: 119

>>>>>>>>>>> Mouse Details <<<<<<<<<<<

Screen: X: 524 Y: 426

Cursor ID: 2

>>>>>>>>>>> Pixel Color Under Mouse <<<<<<<<<<<

RGB: Hex: 0xD4D0C8 Dec: 13947080

>>>>>>>>>>> Control Under Mouse <<<<<<<<<<<

Size: X: 131 Y: 60 W: 75 H: 23

Control ID: 2

ClassNameNN: Button1

Text: OK

Style: 0x50030001

ExStyle: 0x00000004

>>>>>>>>>>> Status Bar Text <<<<<<<<<<<

>>>>>>>>>>> Visible Window Text <<<<<<<<<<<

OK

NIC Address and Computer Name updated Successfully.

>>>>>>>>>>> Hidden Window Text <<<<<<<<<<<

This second one is where I would need it to send enter to the first two dialog boxes, open an ini file, then run an ipconfig /all in a dos box. After closing the .ini file, the autoit script would then run the same program as if it completed successfully.

I know that I'd have to use a WinWaitClose for the notepad window, but I have no idea how to write the script to get the info from the dialog box and then direct the script to the right course of action.

Hope this helps, and thanks a lot! I've tried to understand this, but I'm just getting into any sort of programming. So far, I've done ok with simple straightforward scripts, but I have no idea on this one.

Even if someone gives me a good solid simple script (no offense PerryRaptor) I'd be willing to try and hack away at it to figure out how this works.

Thanks again

SloppyJoe

Link to comment
Share on other sites

Have you tried the command WinGetText ?

$check = ;put what phrase you want to check for here
$text = WinGetText("Untitled -", "")
If $text = $check Then ;what you want it to do if it matches
Edited by BALA
[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com
Link to comment
Share on other sites

Have you tried the command WinGetText ?

Here's what I have so far, sorry for not posting it sooner

CODE
Run("C:\program files\Spector\Get_NIC_Address.exe")

$text = WinGetTitle("", "")

If $text = ("NOT found in Spector Database") Then

Run("notepad.exe C:\program files\spector\spector.ini")

Sleep(500)

Run("cmd.exe")

Sleep(500)

Send("ipconfig /all")

Send("{ENTER}")

WinWaitClose("Spector.ini - Notepad")

Send("{ENTER 2}")

Run("C:\program files\Spector\spector.exe")

ElseIf $text = ("NIC Address and Computer Name updated Successfully") Then

Send("(ENTER)")

Run("C:\program files\Spector\spector.exe")

EndIf

Not sure what I'm doing wrong, as it just goes right on throught line by line as if it ignores the "WinGetTitle" line. I don't need this program to loop, as it can only encounter one of two different dialog boxes which will always come up.

Thanks again

Sloppy

Edited by sloppyjoe72
Link to comment
Share on other sites

Here's what I have so far, sorry for not posting it sooner

CODE
Run("C:\program files\Spector\Get_NIC_Address.exe")

$text = WinGetTitle("", "")

If $text = ("NOT found in Spector Database") Then

Run("notepad.exe C:\program files\spector\spector.ini")

Sleep(500)

Run("cmd.exe")

Sleep(500)

Send("ipconfig /all")

Send("{ENTER}")

WinWaitClose("Spector.ini - Notepad")

Send("{ENTER 2}")

Run("C:\program files\Spector\spector.exe")

ElseIf $text = ("NIC Address and Computer Name updated Successfully") Then

Send("(ENTER)")

Run("C:\program files\Spector\spector.exe")

EndIf

Not sure what I'm doing wrong, as it just goes right on throught line by line as if it ignores the "WinGetTitle" line. I don't need this program to loop, as it can only encounter one of two different dialog boxes which will always come up.

Thanks again

Sloppy

it's probably trying to read the data before either window has a chance to exist. try like this....

Run("C:\program files\Spector\Get_NIC_Address.exe")
While 1
Sleep(10)
If WinExists("NOT found in Spector Database") Then
        Run("notepad.exe C:\program files\spector\spector.ini")
        Sleep(500)
        Run("cmd.exe")
        Sleep(500)
        Send("ipconfig /all")
        Send("{ENTER}")
        WinWaitClose("Spector.ini - Notepad")
        Send("{ENTER 2}")
        Run("C:\program files\Spector\spector.exe")
Exit
    ElseIf WinExists("NIC Address and Computer Name updated Successfully") Then
        Send("(ENTER)")
        Run("C:\program files\Spector\spector.exe")
Exit
    EndIf
WEnd
Edited by cameronsdad
Link to comment
Share on other sites

CODE
Run("C:\program files\Spector\Get_NIC_Address.exe")

Do

$title = WinGetTitle("", "NIC")

Sleep(100)

Until $title = "Get_MAC_And_ComputerName"

If $title = "Get_MAC_And_ComputerName" Then

Send("{ENTER 2}")

Run("notepad.exe C:\fsi\spector\spector.ini")

Sleep(500)

Run("cmd.exe")

Sleep(1000)

Send("ipconfig /all")

Send("{ENTER}")

WinWaitClose("Spector.ini - Notepad")

Run("C:\program files\Spector\spector.exe")

Else

If $title = "Update SQL With NIC and Computer Name" Then

Send("{ENTER}")

Run("C:\program files\Spector\spectrum.exe")

EndIf

EndIf

Managed to hobble this together off someone else's example on the site. The first half runs successfully, but I'm not able to test the second half.

The only thing I wish I could script better is waiting for the dos box to be active. Will try and tackle it tomorrow, but always open to suggestions

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