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

    • 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'
       
    • nacerbaaziz
      By nacerbaaziz
      Hello
      How are you
      I have a question, please.
      I've created a window and i need
      when i run the script if it detect an other copy from the same script was runing
       the script close the first copy Automatically and run a new copy
      I want an example to understand it
    • Nareshm
      By Nareshm
      Please Somebody Help me i am trying to create new script but, i don't know how to create it.

      I am Creating script like this :
      ; My script here [First Script]
      Check the internet connection, if internet connected then
      ; My Script here [Second Script]
      If internet not connected, wait for connect, after connected run my second script
      If Control id/windows/title matched do nothing and end/exit autoit script
      If Control id/windows/title not matched repeat my first and second script again until control id/windows/tittle not matched

      match with :
      >>>> Window <<<<
      Title:    PS :: Version - 2.8.0.0  - [PS Bill]
      Class:    WindowsForm734a
      Position:    -8, -8
      Size:    1382, 744
      Style:    0x17CD0000
      ExStyle:    0x00050100
      Handle:    0x0000000000130572
      >>>> Control <<<<
      Class:    WindowsForm734a
      Instance:    15
      ClassnameNN:    WindowsForm34a15
      Name:    BillPrint
      Advanced (Class):    [NAME:BillPrint]
      ID:    7875
      Text:    
      Position:    39, 310
      Size:    1221, 306
      ControlClick Coords:    745, 20
      Style:    0x56010000
      ExStyle:    0x00000000
      Handle:    0x00000000000C0468
       
    • kawliga751
      By kawliga751
      I am attempting to run an Autoit.exe with schtasks every weekday @ 9:05 am.
      I have the below
      C:\>SchTasks /Create /TN "P10Run" /TR "O:\AUTOIT\P40 Run.au3" /SC WEEKLY /D MON, TUE,WED,THU,FRI /ST 09:05:00 SUCCESS: The scheduled task "P10Run" has successfully been created. I also did a "test" run :
      C:\>Schtasks /Run /TN "P10Run SUCCESS: Attempted to run the scheduled task "P10Run". But when I run my query to verify success my "Last Result" seems to indicate that the script did not run:
      C:\>SCHTASKS /QUERY /FO LIST /V /TN "P10RUN" Folder: \ HostName: xxxxxxxxxxxxxxxx TaskName: \P10RUN Next Run Time: N/A Status: Could not start Logon Mode: Interactive only Last Run Time: 6/14/2017 9:08:56 AM Last Result: -2147024894 Author: xxxxxxx Task To Run: O:\AUTOIT\P40 Run.au3 Start In: N/A Comment: N/A Scheduled Task State: Enabled Idle Time: Disabled Power Management: Stop On Battery Mode, No Start On Batterie s Run As User: xxxxxxxxx\xxxxxxxx Delete Task If Not Rescheduled: Enabled Stop Task If Runs X Hours and X Mins: 72:00:00 Schedule: Scheduling data is not available in this f ormat. Schedule Type: Weekly Start Time: 9:05:00 AM Start Date: 6/14/2017 End Date: N/A Days: MON, TUE, WED, THU, FRI Months: Every 1 week(s) Repeat: Every: Disabled Repeat: Until: Time: Disabled Repeat: Until: Duration: Disabled Repeat: Stop If Still Running: Disabled C:\> Is there something missing in my command? Also is there a better way to make sure that the script does in fact sun successfully?
      Thanks In Advance! 
    • chacoya121
      By chacoya121
      please help, how to write script for multiple choice question
      in GUI
      -single program
      -add more question to program
      example:
      1. this is the question
      a. answer a
      b. answer b
      c. answer c
      d.answer d
      - 300 questions +  700 answers
      please give me some tips to create a script
      read and write file from notepad, that mean u need notepad attach?