Jump to content

"Send" functions works on some computers, not others


 Share

Recommended Posts

I created an AutoIt script that performs an unattended installation of All the Right Type 3 Plus. The "AutoIt Window Info" tool doesn't provide information about the All the Right Type 3 Plus installer's controls, which means that I couldn't use functions like "ControlSetText". Instead, I had to use less reliable functions such as "Send". The very first screen of the installer is where you enter the activation code. My AutoIt script enters the activation code using the "Send" function. Here's the problem: when I run the AutoIt script on my laptop's virtual machine (host: Windows 7 Professional, guest: Windows XP Professional), it works just fine. When I run the AutoIt script on my desktop computer (Windows XP Professional), it works just fine. However, I've tried it on about five other computers (all with Windows XP Professional), and the "Send" function doesn't send the activation code! The All the Right Type 3 Plus installer is active and the text field is in focus, so why wouldn't it be working? I would really appreciate help. Thanks!

Here is my code:

$SoftwareTitle = "All the Right Type 3 Plus"

If $CmdLine[0] > 0 And FileExists($CmdLine[1]) Then
    $PathToInstaller = $CmdLine[1]
Else
    If $CmdLine[0] == 0 Then
        $MessageText = "The location for the " & chr(34) & $SoftwareTitle & chr(34) & " installer was not specified. "
    Else
        $MessageText = "The following file was not found:" & @CRLF & @CRLF & chr(34) & $CmdLine[1] & chr(34) & @CRLF & @CRLF
    EndIf

    $Choice = MsgBox(52, "Alert", $MessageText & "Would you like to specify the location of the installation program now?")

    If Not ($Choice == 6) Then
        Exit(1)
    EndIf

    $PathToInstaller = FileOpenDialog("Choose the installer", "", "Programs (*.exe;*.msi)", 1)
EndIf

If $CmdLine[0] > 1 And (StringLower($CmdLine[2]) == "staff" Or StringLower($CmdLine[2]) == "student") Then
    $StaffOrStudent = StringLower($CmdLine[2])
Else
    If $CmdLine[0] < 2 Then
        $MessageText = "The program type (teacher or student) was not specified."
    Else
        $MessageText = "The program type you specified (" & $CmdLine[2] & ") was not valid."
    EndIf

    $Choice = MsgBox(51, "Alert", $MessageText & @CRLF & @CRLF & "The teacher program takes up 15 MB more than the student program. It has all of the same features with the addition of the Maintenance Building to allow the teacher to add / modify / review class and student records." & @CRLF & @CRLF & "Would you like to install the teacher program?")

    If $Choice == 6 Then
        $StaffOrStudent = "staff"
    ElseIf $Choice == 7 Then
        $StaffOrStudent = "student"
    Else
        Exit(1)
    EndIf
EndIf

Run($PathToInstaller)

WinWait("[TITLE:Setup; CLASS:ImlWinCls]", "", 60)

If WinExists("[TITLE:Setup; CLASS:ImlWinCls]") Then
    BlockInput(1)
    AutoItSetOption("MouseCoordMode", 0)
    WinActivate("[TITLE:Setup; CLASS:ImlWinCls]")
    Sleep(2000)

    # Welcome screen: enter activation code and push enter
    Send("MYCODE{Enter}")

    # Software License Agreement screen: click the "Yes" button
    MouseMove(560, 370)
    MouseClick("primary")
    Sleep(2000)

    # Registration screen: click the "Next >>" button
    MouseClick("primary")
    Sleep(2000)

    # Installation Type screen: choose "Local Install (Networking required)" and click the "Next >>" button
    MouseMove(228, 254)
    MouseClick("primary")
    MouseMove(560, 370)
    MouseClick("primary")
    Sleep(2000)

    # Choose a Program screen: choose "Teacher Program" or "Student Program" and click the "Next >>" button
    If $StaffOrStudent = "student" Then
        MouseMove(242, 272)
        MouseClick("primary")
        MouseMove(560, 370)
    EndIf

    MouseClick("primary")
    Sleep(2000)

    # Choose a Size of Screen screen: click the "Next >>" button
    MouseClick("primary")
    Sleep(2000)

    # Destination Folder screen: click the "Next >>" button
    MouseClick("primary")
    Sleep(2000)

    # Icon Settings screen: click the "Next >>" button
    MouseClick("primary")
    Sleep(2000)

    # Confirm Current Settings screen: click the "Install" button
    MouseClick("primary")
    Sleep(2000)

    # Wait for up to 30 minutes for the "ATRT 3 Plus" folder to open, which indicates that the installation process is done
    WinWait("[TITLE:ATRT 3 Plus; CLASS:CabinetWClass]", "", 1800)

    # Close the "ATRT 3 Plus" folder
    If WinExists("[TITLE:ATRT 3 Plus; CLASS:CabinetWClass]") Then
        WinActivate("[TITLE:ATRT 3 Plus; CLASS:CabinetWClass]")
        Sleep(2000)
        Send("!{F4}")
    EndIf

    WinActivate("[TITLE:Setup; CLASS:ImlWinCls]")
    Sleep(2000)

    # Setup Complete screen: uncheck the "Yes, finish the setup program and view the ReadMe file." checkbox and click the "Finish" button
    MouseMove(321, 235)
    MouseClick("primary")
    MouseMove(560, 370)
    MouseClick("primary")

    BlockInput(0)

    If Not ($CmdLine[0] == 2) Then
        MsgBox(64, "Reminder", "Don't forget to open " & $SoftwareTitle & " and enter the IP address of the server where the database is located!")
    EndIf
Else
    Exit(1)
EndIf
Link to comment
Share on other sites

You can use ControlSend() without a control ID, the synthetic keyboard input will go to the window, which should apply it to the control with current focus even if you can't identify that control.

$hWin = WinGetHandle("[TITLE:Setup; CLASS:ImlWinCls]", "")
ControlSend($hWin, "", "", "Some input to send...")

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...