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

    • dumbledown
      By dumbledown
      Hi,
      I'm new to AutoIt but it looks great.
      I want to get the text from Internet Explorer when hovering the mouse over an image, the statusbargettext function appears to be the way to go.
      When running via a hotkey I return a blank, but the msgbox works. Do you know what I'm doing wrong?
      Thanks
      HotKeySet("!x", "RecordURL") ;wait for ALT-a keystroke While 1 ;loop forever to wait for the keypress Sleep(100) ;no need to kill the CPU WEnd Func RecordURL() #include <MsgBoxConstants.au3> AutoItSetOption("WinTitleMatchMode", 2) Local $sText = StatusbarGetText("Internet Explorer") MsgBox($MB_SYSTEMMODAL, "", "Internet Explorer's status bar says: " & $sText) EndFunc  
       
    • barkeeper
      By barkeeper
      Hi there, not sure if this is the right place, but I'm building a script for using premade answers in chat. It works and outputs the answers (stored in an ini file based on:  answer name = answer it also works with a new line if there is a tag <enter> in the answer text in the ini file. Now the problem is, that after the answer is pasted in the chat (you bring up the interface with ctrl+1) it gives an enter, thus sending the output straight away. I would like to be able to review the answer before sending it. can anyone help me by telling what's wrong in the script, I tried replacing the @crlf in the script with other options, no luck. Thanks in advance! 
      antwoorden.au3
      antwoorden.ini
    • EdyYusof
      By EdyYusof
      Hi,
      I newbie here, my english not so good
      my first post and first script,
      I learn make sofware with autoit, and to want share with other forumer
      just simple autoit script in my first try
      (and not full follow autoit format(yet, in learning and understand))
      Screenshot  http://www.xyplorer.com/xyfc/download/file.php?id=9726
       
      #include <Array.au3> #include <IE.au3> #NoTrayIcon Global $g_sUrlList, $g_sHelpPath, $g_sNavPath, $g_sKeyword, $hWnd, $g_RegexP Global $sChmUrl_L, $g_sClipbord, $sFileN $sFileN = StringRegExpReplace(@ScriptFullPath, "(.+\\)([^\\]+)\.(au3|a3x|exe)", "$2", 1) $sSDir = StringRegExpReplace(@ScriptFullPath, "(.+\\)[^\\]+\.(au3|a3x|exe)", "$1", 1) Global Const $g_sIniPath = $sSDir & '_IncludePart\' & $sFileN & '.ini' _sClipGet() $sTitl = WinGetTitle("[ACTIVE]") $sExt = StringRegExpReplace($sTitl, "(.+\.)(\w{1,6}).*", "$2", 1) Local $sCount, $sDefault $sCext = "~" $i = 0 $pi = 1 If FileExists($g_sIniPath) = 0 Then _IniWriteSection() Sleep(1000) EndIf If FileExists($g_sIniPath) = 1 Then $j = 0 $sCount = IniRead($g_sIniPath, "MainHChmData", "TotalItems", "") Do $j += 1 $sKeyt = " " & IniRead($g_sIniPath, "HChmData" & $j, "FileExt", "") Until $j = 20 Or $sKeyt = " " $j -= 1 If $sCount <> $j Then IniWrite($g_sIniPath, "MainHChmData", "TotalItems", $j) $sCount = $j EndIf $sDefault = IniRead($g_sIniPath, "MainHChmData", "DefaultItems", "") For $i = 1 To $sCount Local $sCext = " " & IniRead($g_sIniPath, "HChmData" & $i, "FileExt", "") $Cext = StringInStr($sCext, $sExt & ";") If $Cext > 1 Then ExitLoop EndIf Next EndIf If $sCext = "~" Or $sDefault = "" Then $sDefault = 1 If $i > $sCount Then $i = $sDefault $g_sHelpPath = IniRead($g_sIniPath, "HChmData" & $i, "HChmPath", "") $hWndT = '[' & IniRead($g_sIniPath, "HChmData" & $i, "hWnd", "") & ']' $g_sNavPath = IniRead($g_sIniPath, "HChmData" & $i, "ChmUrlList", "") $sDef = IniRead($g_sIniPath, "HChmData" & $i, "DefaultPage", "") $g_RegexP = IniRead($g_sIniPath, "HChmData" & $i, "RegexMatches", "") If FileExists($g_sHelpPath) = 0 Or FileExists($g_sNavPath) = 0 Or $hWndT = "[]" Then MsgBox(0, "Missing Or Invalid Path :", "Note: Make Sure Correct Ini Data In : " & @CRLF & $g_sIniPath & @CRLF & @CRLF & "Bellow Information Data :" & @CRLF & @CRLF & "HelpFile.chm : " & @CRLF & $g_sHelpPath & @CRLF & @CRLF & "ChmUrlList : " & @CRLF & $g_sNavPath & @CRLF & @CRLF & "HelpWindowsHwnd : " & @CRLF & $hWndT & @CRLF) EndIf $sChf = "::" & $sDef If $sDef = "" Then $sChf = "" If WinExists($hWndT) = 0 Then Run('"hh.exe" "' & $g_sHelpPath & $sChf & '"') WinWaitActive($hWndT) Sleep(500) EndIf $hWnd = WinGetHandle($hWndT) If IsHWnd($hWnd) = 0 Then MsgBox(0, "Not Valid Help Windows Hwnd", 'Make Sure Correct Help Windows Hwnd' & @CRLF & @CRLF & "HelpWindowsHwnd : " & @CRLF & $hWndT & @CRLF & @CRLF & "Sample Correct Hwnd (Windows Help Title & Class)" & @CRLF & "REGEXPTITLE:AutoIt Help.+; REGEXPCLASS:HH Parent" & @CRLF & "OR" & @CRLF & "TITLE:AutoIt Help (v3.3.14.2); CLASS:HH Parent") EndIf _sGetUrl() Exit Func _IniWriteSection() If FileExists($g_sIniPath) = 0 Then DirCreate(@ScriptDir & "\_IncludePart") EndIf Local $sAutoItInstallDir = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & ((@OSArch = 'X64') ? "\Wow6432Node" : "") & "\AutoIt v3\AutoIt", "InstallDir") If $sAutoItInstallDir = "" Then $sAutoItInstallDir = "Replace This Note In _IncludePart\" & $sFileN & ".Ini File With Valid Path " Local $aGeneral[3][2] = [[2, ""], ["TotalItems", "1"], ["DefaultItems", "1"]] Local $aSection[7][2] = [[5, ""], ["HChmPath", $sAutoItInstallDir & "\AutoIt.chm"], ["hWnd", "REGEXPTITLE:AutoIt Help.+; REGEXPCLASS:HH Parent"], _ ["ChmUrlList", @ScriptDir & "\_IncludePart\HHChmAutoIt3.au3t"], ["FileExt", "au3;a3x;"], ["DefaultPage", "html/functions/Window Management.htm"], _ ["RegexMatches", ""]] IniWriteSection($g_sIniPath, "MainHChmData", $aGeneral) IniWriteSection($g_sIniPath, "HChmData1", $aSection) EndFunc ;==>_IniWriteSection Func _sClipGet() $ClipBord = ClipGet() ClipPut("") Sleep(10) Send("^c") $g_sClipbord = ClipGet() ClipPut($ClipBord) Local $iLength = StringLen($g_sClipbord) EndFunc ;==>_sClipGet Func _sGetUrl() Local $iLength = StringLen($g_sClipbord) $aData = StringRegExp($g_sClipbord, '[^"()$\s\n]+', $STR_REGEXPARRAYFULLMATCH) If $aData = 1 Then MsgBox(0, "Abort :", "Clipbord : " & $g_sClipbord & @CRLF & @CRLF & "Noting Selected Or Macth With Regex" & @CRLF & @CRLF) Exit EndIf $g_sKeyword = StringLower(StringFormat("%s", $aData[0])) $iLength2 = StringLen($g_sKeyword) If $iLength2 < 3 Then MsgBox(0, "Note :", "Abort : Word Letter Below 4" & @CRLF & "Seleted = " & $g_sKeyword & @CRLF & "Length = " & $iLength2) Exit Else _aFileRead($g_sNavPath) _sChmUrl() EndIf EndFunc ;==>_sGetUrl Func _sChmUrl() $Reg = '(?i)([^\n]+' & $g_sKeyword & '[^\n]*)' _StringRegex($g_sUrlList, $Reg) $aRegx = "[^\n]+/()\.htm;;[^\n]+/()\w\w?\.htm;;[^\n]+#();;[^\n]+#()\w\w?;;[^\n]+/()[^\n/]+\.htm;;[^\n]+#[^\n#/]*()[^\n]*;;[^\n]+/[^\n/]+()[^\n/]*\.htm;;[^\n]+()[^\n/]*\r" If $g_RegexP <> "" Then $aRegx = $g_RegexP & ";;" & $aRegx EndIf $aRegx = StringSplit("(" & StringReplace(StringReplace($aRegx, "()", $g_sKeyword), ";;", "\r)¦(") & "\r)", "¦", 1) _StringRegexUrl($sChmUrl_L, $aRegx) Exit EndFunc ;==>_sChmUrl Func _NavigateCHM($sFilePath, $sSection) If IsHWnd($hWnd) Then Local $oIE = _IEAttach($hWnd, 'Embedded') _IENavigate($oIE, 'mk:@MSITStore:' & $sFilePath & '::/' & $sSection) WinActivate($hWnd) ; ControlFocus($hWnd,"","[ID:201]") ; ControlClick($hWnd,"","[ID:201]","",1,625, 155) ; ControlClick($hWnd,"","[CLASS:Button; TEXT:Hide;]","") EndIf Exit EndFunc ;==>_NavigateCHM Func _StringRegexUrl($sList, $aRegx) Local $sChmUrl For $i = 1 To $aRegx[0] - 1 $sChmUrl = StringRegExp($sList, '(?i)' & $aRegx[$i], 1) If IsArray($sChmUrl) Then $sChmUrl = StringTrimRight($sChmUrl[0], 1) _NavigateCHM($g_sHelpPath, $sChmUrl) EndIf Next Exit EndFunc ;==>_StringRegexUrl Func _StringRegex($sConten, $Reg) $aGetChmUrl = StringRegExp($sConten, $Reg, 3) If $aGetChmUrl = 1 Then MsgBox(0, "Abort :", "Keyword : " & $g_sKeyword & @CRLF & @CRLF & "Noting Macth Any Chm Url By Keyword" & @CRLF & @CRLF) Exit Else $sCChm = UBound($aGetChmUrl) For $i = 0 To $sCChm - 1 $sChmUrl_L &= $aGetChmUrl[$i] & @CRLF Next EndIf Return $sChmUrl_L EndFunc ;==>_StringRegex Func _aFileRead($g_sNavPath) Local $hFileOpen = FileOpen($g_sNavPath, $FO_READ) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.") Return False EndIf $g_sUrlList = FileRead($hFileOpen) FileClose($hFileOpen) Return $g_sUrlList EndFunc ;==>_aFileRead  
       

      LearningTools.7z
      Info in ReadMe.txt
      Just to ask other forumer,
      Correct way or keyword command to autoit click Hide button in AutoIt.chm windows?
          ControlFocus($hWnd,"","[ID:201]")
          ControlClick($hWnd,"","[ID:201]","left",1)
          ControlClick($hWnd,"","[CLASS:Button; TEXT:Hide;]","left",1)
      I try using ControlClick, sendkey or mouseclick, but not work
       
       
       
      LearningTools.7z
    • Masum
      By Masum
      Hi all,
      Ctrl+Break stops script only if AutoIt window is active. It doesn't work while automation is going on elsewhere.
      Is there a way to stop the script regardless of where the automation is happening?
      Thanks
    • Vivaed
      By Vivaed
      Trying to automate the sideload of a Windows Store app via .ps1 script...
      RunWait(@ComSpec & ' /c' & 'C:\"WB Resources"\APP_Prod\Add-AppDevPackage.ps1') Above doesn't work... I assume this is trying to open in CMD.
       
      Normally we right click the .ps1 and open with powershell, then we have to type "A" to start the install, it installs and then type any yet to exit.
      However I cant get the powershell to even open.
      Kind of puzzled here, any suggestions would be a help.
      PS I also tried to convert the .ps1 to exe, but that was a huge failure... lol