Sign in to follow this  
Followers 0
4evrplan

Scheduled Task - Script Won't Finish

6 posts in this topic

First the Situation:

I'm trying to automate an image uploading utility which lives on the client side of some cloud based server/client software and which was not designed to be automated. I've got a 2012 R2 VM running with autologon enabled on a local account.  The account with autologon enabled has a scheduled task set up to run at 4AM daily.  This task merely runs my AutoIt script.

Now the issue:

If I remote into my VM and run the script manually, it runs perfectly. If I edit my scheduled task to run only a few minutes in the future, and then reboot the VM, it also works perfectly. If I leave it to run overnight, the script starts but never finishes. It seems to be getting hung up waiting for the first window to become active. I've tried many version of the script now with no luck.  The latest version is below.

#include <File.au3>

Dim $un = "username"
Dim $pw = "password"

; Login window
Run("C:\Program Files (x86)\CSI Software\Spectrum NG\Spectrum NG Client\SNGImageUploader.exe")
Dim $hLogin = WinWait("[CLASS:WindowsForms10.Window.8.app.0.2bf8098_r11_ad1]", "Version: ")
SendKeepActive($hLogin)
WinActivate($hLogin)
Send($un & "{TAB}" & $pw & "{ENTER}")
SendKeepActive("")

; Main window - 1/3
Dim $hMain = WinWaitActive("SNG Image Uploader")
SendKeepActive($hMain)
Send("{TAB}{ENTER}")
SendKeepActive("")

; File browser window
Dim $hBrowse = WinWaitActive("Browse For Folder")
SendKeepActive($hBrowse)
Send("{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{RIGHT}{DOWN}")
Sleep(2000)  ; Give the program moment to detect images in the directory
Send("{ENTER}")
SendKeepActive("")

; Main window - 2/3
SendKeepActive($hMain)
WinWaitActive($hMain)
Send("{TAB}{ENTER}")
SendKeepActive("")

; Upload complete window
Dim $hUpload = WinWaitActive("[CLASS:#32770]", "Upload complete. Please wait while servers process your request.")
SendKeepActive($hUpload)
Send("{ENTER}")
SendKeepActive("")

; Import complete window
Dim $hImport = WinWaitActive("[CLASS:#32770]", "Image import completed. Please check results in the Account Upload History screen.")
SendKeepActive($hImport)
Send("{ENTER}")
SendKeepActive("")

; Main window - 3/3
WinWaitActive($hMain)
WinClose($hMain)

; Cleanup
FileDelete("C:\CRPics\*")

 

Share this post


Link to post
Share on other sites



I've added extensive logging to my script.  Here's the new version:

#include <File.au3>

Dim $un = "username"
Dim $pw = "password"

Dim $flog = FileOpen("C:\Users\CRPics\Desktop\SendCRPics.log", 1);
_FileWriteLog($flog, "")

; Login window
_FileWriteLog($flog, "Running SNGImageUploader")
Run("C:\Program Files (x86)\CSI Software\Spectrum NG\Spectrum NG Client\SNGImageUploader.exe")
_FileWriteLog($flog, "Waiting for the login window to exist")
Dim $hLogin = WinWait("[CLASS:WindowsForms10.Window.8.app.0.2bf8098_r11_ad1]", "Version: ")
_FileWriteLog($flog, "Attempting to keep the login window active")
SendKeepActive($hLogin)
_FileWriteLog($flog, "Activating the login window")
WinActivate($hLogin)
_FileWriteLog($flog, "Logging in")
Send($un & "{TAB}" & $pw & "{ENTER}")
_FileWriteLog($flog, "Clearing SendKeepActive state")
SendKeepActive("")

; Main window - 1/3
_FileWriteLog($flog, "Waiting for the main window to become active")
Dim $hMain = WinWaitActive("SNG Image Uploader")
_FileWriteLog($flog, "Attempting to keep the main window active")
SendKeepActive($hMain)
_FileWriteLog($flog, "Clicking the browse button")
Send("{TAB}{ENTER}")
_FileWriteLog($flog, "Clearing the SendKeepActive state")
SendKeepActive("")

; File browser window
_FileWriteLog($flog, "Waiting for the file browser window to become active")
Dim $hBrowse = WinWaitActive("Browse For Folder")
_FileWriteLog($flog, "Attempting to keep the file browser window active")
SendKeepActive($hBrowse)
_FileWriteLog($flog, "Browsing to the image directory")
Send("{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{RIGHT}{DOWN}")
_FileWriteLog($flog, "Waiting for the program to read the image directory")
Sleep(2000)  ; Give the program moment to detect images in the directory
_FileWriteLog($flog, "Choosing the directory")
Send("{ENTER}")
_FileWriteLog($flog, "Clearing the SendKeepActive state")
SendKeepActive("")

; Main window - 2/3
_FileWriteLog($flog, "Attempting to keep the main window active")
SendKeepActive($hMain)
_FileWriteLog($flog, "Waiting for the main window to become active")
WinWaitActive($hMain)
_FileWriteLog($flog, "Clicking the upload button")
Send("{TAB}{ENTER}")
_FileWriteLog($flog, "Clearing the SendKeepActive state")
SendKeepActive("")

; Upload complete window
_FileWriteLog($flog, "Waiting for the 'upload complete' dialog to become active")
Dim $hUpload = WinWaitActive("[CLASS:#32770]", "Upload complete. Please wait while servers process your request.")
_FileWriteLog($flog, "Attempting to keep the 'upload complete' dialog active")
SendKeepActive($hUpload)
_FileWriteLog($flog, "Clicking OK")
Send("{ENTER}")
_FileWriteLog($flog, "Clearing the SendKeepActive state")
SendKeepActive("")

; Import complete window
_FileWriteLog($flog, "Waiting for the 'import complete' dialog to become active")
Dim $hImport = WinWaitActive("[CLASS:#32770]", "Image import completed. Please check results in the Account Upload History screen.")
_FileWriteLog($flog, "Attempting to keep the 'import complete' dialog active")
SendKeepActive($hImport)
_FileWriteLog($flog, "Clicking OK")
Send("{ENTER}")
_FileWriteLog($flog, "Clearing the SendKeepActive state")
SendKeepActive("")

; Main window - 3/3
_FileWriteLog($flog, "Waiting for the main window to become active")
WinWaitActive($hMain)
_FileWriteLog($flog, "Closing the program")
WinClose($hMain)

; Cleanup
_FileWriteLog($flog, "Deleting images from the image directory")
FileDelete("C:\CRPics\*")

FileClose($flog);

 

Share this post


Link to post
Share on other sites

Maybe it helps when you also share the result of your logging? ;)

In general: Send() will not work when ran with the scheduler so you need to find a way to use CtrlSend()

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Odd that it works when I schedule it for just a few minutes into the future then.  I'll post tomorrow when I get the log results.  I tried using ControlSend() in at least one version of the script, but I couldn't get it to work for the username/password boxes on the login screen.  Granted I'm a total novice, so I'll try again if I don't figure something else out really quick after looking at the log in the morning.

Share this post


Link to post
Share on other sites

Oops - I forgot to restart the VM.  I left it logged into an RDP session all night.  The good news is it finished successfully, but it's not a good test of a typical run situation.  I played around a bit more with ControlSend() yesterday, and I think I'm getting it figured out, so I'm going to change the script to get rid of all the calls to Send().

Share this post


Link to post
Share on other sites

I got it working. The key was to switch to ControlSend() away from Send() as suggested. Thank you Jos. Here's the latest, hopefully final, version:

#include <File.au3>

Dim $un = "username"
Dim $pw = "password"

; Login window
Run("C:\Program Files (x86)\CSI Software\Spectrum NG\Spectrum NG Client\SNGImageUploader.exe")
Dim $hLogin = WinWait("[CLASS:WindowsForms10.Window.8.app.0.2bf8098_r11_ad1]", "Version: ")
ControlSend($hLogin, "", "[CLASS:WindowsForms10.EDIT.app.0.2bf8098_r11_ad1; INSTANCE:1]", $un & "{TAB}")
Sleep(1000)
ControlSend($hLogin, "", "[CLASS:WindowsForms10.EDIT.app.0.2bf8098_r11_ad1; INSTANCE:1]", $pw)
Sleep(1000)
ControlClick($hLogin, "", "[CLASS:WindowsForms10.Window.8.app.0.2bf8098_r11_ad1; INSTANCE:4]")

; Main window - 1/3
Dim $hMain = WinWait("SNG Image Uploader")
ControlClick($hMain, "", "[CLASS:WindowsForms10.BUTTON.app.0.2bf8098_r11_ad1; INSTANCE:6]")

; File browser window
Dim $hBrowse = WinWait("Browse For Folder")
Sleep(10000)
ControlSend($hBrowse, "", "[CLASS:SysTreeView32; INSTANCE:1]", "{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{RIGHT}{DOWN}")
Sleep(2000)  ; Wait for the program to read the image directory
ControlClick($hBrowse, "", "[CLASS:Button; INSTANCE:2]")
Sleep(2000)

; Main window - 2/3
ControlClick($hMain, "", "[CLASS:WindowsForms10.BUTTON.app.0.2bf8098_r11_ad1; INSTANCE:5]")

; Upload complete window
Dim $hUpload = WinWait("[CLASS:#32770]", "Upload complete. Please wait while servers process your request.")
ControlClick($hUpload, "", "[CLASS:Button; INSTANCE:1]")

; Import complete window
Dim $hImport = WinWait("[CLASS:#32770]", "Image import completed. Please check results in the Account Upload History screen.")
ControlClick($hImport, "", "[CLASS:Button; INSTANCE:1]")

; Main window - 3/3
WinClose($hMain)

; Cleanup
FileDelete("C:\CRPics\*")

 

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

  • Similar Content

    • comtech80
      By comtech80
      Folks,
      I have an issue I've been trying to solve for a while, I'm trying to add static routes in DHCP via a 121 route rule in Windows 2012 R2 is a brutal manual process and wanted to automate this via AutoIT.
       
      When I use the "ControlGetText" everything displays properly in the MSG box but when I try and use "ControlSetText" or "ControlSend" the values won't display in the input box but the action comes back as successful?
      Anyone able to help me with this? I'm thinking this might be an active window issue but i'm not sure.
      Here is a part of my code.
       
      $hWnd = WinWait("[TITLE:Add a Static Route]","", 10)
      WinActivate($hWnd)
      $Status = ControlSend($hWnd, "", "[CLASS:Edit; INSTANCE:4]", "192"); Does not add 192 to the text box.
      Local $sTextEdit1 = ControlGetText($hWnd, "", "[CLASS:Edit; INSTANCE:1]")
      ConsoleWrite ( "ControlSend Status: " &  $Status & @CRLF); Returns a Value of 1
      ConsoleWrite ( "ControlGetText Value Edit1: " &  $sTextEdit1 & @CRLF);
       
      Please see attachment for more info.

    • ur
      By ur
      I have a button control as below screen.

      This one I am able to suppress using below code in all the OS.
      But on server 2008, sometimes the button highlighted in the image is not getting clicked and some times it is working.
      I have cross checked the IDs when it is not working, but it is working only.
       
      $win1 = "erwin Mart Configuration" $MartConfigWindow = _WinWaitActivate1($win1,"Database Details") ControlSetText($MartConfigWindow, "", "WindowsForms10.EDIT.app.0.378734a6", $dbserver) ControlSetText($MartConfigWindow, "", "WindowsForms10.EDIT.app.0.378734a4", $dbname) ControlSetText($MartConfigWindow, "", "WindowsForms10.EDIT.app.0.378734a9", $dbuser) ControlSetText($MartConfigWindow, "", "WindowsForms10.EDIT.app.0.378734a8", $dbpassword) ;Button clicl logic $iControlClickStatus = ControlClick($MartConfigWindow, "", "[CLASS:WindowsForms10.BUTTON.app.0.378734a; INSTANCE:2]") ;If above button click fails, trying with mouse click on the control if ControlFocus($MartConfigWindow, "", "WindowsForms10.BUTTON.app.0.378734a2")=1 then ;sometimes above button fails in win server 2008,so this loop Send("{ENTER") EndIf  
      Any suggestion on how to resolve this.?
    • Eggsplorer
      By Eggsplorer
      Hi,
      Ich hab ein Script für Windows Updates, dass nach dem OOBE aufgerufen werden soll. Run/RunOnce ist daher nicht möglich.
      Stattdessen möchte ich das Script in den Autostart schreiben lasse. Wenn die OOBE beendet wird und der Administrator angemeldet wird, soll das Update-Script einmalig aufgerufen werden und sich anschl. selbst löschen.
      Lang rede, kurzer Sinn:
      Wie kann ich folgendes Script in den Autostart schreiben?
      RunWait(@ComSpec & " /c " & "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\UA\Scripts\win-updates.ps1 -MaxUpdatesPerCycle 100 -RestartRequired 1", "") Ich würde ungern eine BAT oder EXE reinkopieren, da ich es unsauber finde. Die müsste ja auch zusätzlich irgendwo liegen.
      Danke
      Eggsplorer
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I worked a bit on a little project of mine, and I managed to do what I was trying to do, or, automate a quiz in AutoIt.
      Now, everything works fine but, in order to achieve what I'm trying to achive, I'd like to make this script run faster.
      I'll attach a portion of the code in order to let you understand what my script does.
      $objIE_h1 = _IETagNameGetCollection($objIE, "h1") ; Take the text of the answer If @error Then ConsoleWrite("Errore durante la lettura degli h1 nella pagina. - Errore: " & @error & @CRLF) Else For $objElement In $objIE_h1 $strInnerText = $objElement.innerText Next Select Case StringInStr($strInnerText, "QUESTION") ; Here is the question ; PS4 PRO $objSpans = _IETagNameGetCollection($objIE, "span") ; Answers are stored here For $objElement In $objSpans If $i >= 4 Then $strAnswer = $objElement.innerText ; Take the text of the answer n° 0, 1, 2, 3 If StringInStr($strAnswer, "CORRECT ANSWER") Then ; If I match the correct answer, then, I have to click on the input with answer id = answer_i $j = $i - 4 $objInput = _IEGetObjById($objIE, "answer_" & $j) If @error Then ConsoleWrite("Errore durante la lettura della risposta #" & $i & " - Errore: " & @error & @CRLF) Else _IEAction($objInput, "click") If @error Then ConsoleWrite("Errore durante il click sull'elemento. - Errore: " & @error) Else ConsoleWrite($j & ") Risposta: " & $strAnswer & @CRLF) ExitLoop EndIf EndIf EndIf $i+=1 Else $i+=1 EndIf Next $i = 0 $j = 0 This is what my script does.
      Questions are 20, in which I have 15 multiple choice question, 2 images ( on which I use _IEImgClick() ), and 3 text inputs ( a simple send with the text I have to enter ).
      How can I make all of these, faster?
      If I reach this goal, I've probably done one of my best goals in life, and I'd like to share my happiness with you, giving a huge donation to this fantastic community!
      Thanks for your help
    • au3leecher
      By au3leecher
      Hellow everybody,
      I tryed to manipulate a game called "Assault Cube" which is a easy beginning in coding. I run the code but the wished value doesn't change, i don't understand why.
      The Pointers are fine, I checked that the pointers don't change every time while restart the game.
      My Code:
      <snip>
      _____________________________________________________________________________________________________________________________________________________________________________________________
      Checklist:
      The Offsets are 18C & 4
      In Cheat Engine: ("ac_client.exe"+0010F418) <- Pointer
      4 Bytes = 'dword'