Jump to content

Basic Install Script


Recommended Posts

Hi Guys I am trying to automate an installation process and want to use AutoIT to simulate several keystrokes during the process. I can get my script to open the install application and then I have it set to simulate the ENTER key being pressed, however the program just sits there like the keystroke hasnt been sent. I am new to scripting and dont really have much knowledge so any help would be appreciated.

;Install SolarWinds TFTP Server

run ("L:\SolarWinds\SolarWinds-TFTP-Server.exe")

WinWait ("SolarWinds TFTP Server")

send ("{ENTER}")

WinWaitActive ("SolarWinds TFTP Server", "End User License Agreement")

send ("{TAB}{ENTER}")

WinWaitActive ("SolarWinds TFTP Server", "Destination Location")

send ("{ENTER}")

That is the script as you can see Im not trying to do anything more then have a couple keystrokes simulated but the program is called opens and then just sits there, can someone help identify why the enter key is not being simulated to move the installer along?

Link to comment
Share on other sites

Just replace the first send in your code that does not error, with a MsgBox, see if it appears.

Its just a simple way to find out where the problem is.

If you see it, then move the msgbox further down your code, under send.

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

Am I able to identify the window by like a PID or another identifier of some sorta other then window name? Instead of saying wait for the window by the name of SolarWinds TFTP server to be active say like wait for PID 1111 to be active?

Not realy, but you can list all windows and get the PID of the process that spawned the window, so with that you can loop through all windows untill you find a matching PID.

I made two functions to do so:

#region Example
Global $PID = Run("notepad.exe")
Global $hWnd = _hWndFromPIDWait($PID)
If Not $hWnd Then Exit
WinWaitActive($hWnd)
ControlSend($hWnd, "", "Edit1", "This is a line of text in the notepad window")
#endregion

;Returns the handle to a window associated with a process ID as returned by Run(), if that window exists.
;Usage of $vTitle and $vText is identical to Winlist and can be used if a  program spawns multiple windows, or possibly to speed the function up.
;Returns 0 and sets @error if there is no matching window.
Func _hWndFromPID($PID, $vTitle = "", $vText = "")
    Local $ahWnd = WinList($vTitle, $vText)
    For $i = 1 To $ahWnd[0][0]
        If WinGetProcess($ahWnd[$i][1]) = $PID Then Return $ahWnd[$i][1]
    Next
    Return SetError(1,0,0)
EndFunc

;Waits untill a window associated with a process ID exists and returns the handle.
;Usage of $vTitle and $vText is identical to Winlist and can be used if a  program spawns multiple windows, or possibly to speed the function up.
;Returns 0 and sets @error if timeout occurs before a window is found.
Func _hWndFromPIDWait($PID, $vTitle = "", $vText = "", $iTimeOut = 0)
    Local $ahWnd
    Local $iTimer = TimerInit()
    While 1
        $ahWnd = WinList($vTitle, $vText)
;~      _ArrayDisplay($ahWnd)
;~      Exit
        For $i = 1 To $ahWnd[0][0]
            If WinGetProcess($ahWnd[$i][1]) = $PID Then Return $ahWnd[$i][1]
        Next
        If $iTimeOut And $iTimeOut > TimerDiff($iTimer) Then Return SetError(1,0,0)
    WEnd
EndFunc
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...