JJohnson Posted March 11, 2015 Share Posted March 11, 2015 Hello I recently got a new PC at work and a script I created years ago stopped working. Specifically the script seems unable to find an open window using: If WinExists("[REGEXPTITLE:(?i).*Processing.*?]") Then Local $hWnd1 = WinGetHandle("[REGEXPTITLE:(?i).*Processing.*?]") WinWaitNotActive($hWnd1, "",150) EndIf The program I'm monitoring is running 3 reports for me. I don't want to sit here and run and export them myself 3x a day everyday, so this script was written to handle it for me. When I moved to the Win7 PC I just copied my script and downloaded the latest version of AutoIT. I'm running this directly from the editor. Here's most of the code to wait on the processing windows to close and then perform a mouse click to export the report: Sleep(500) ;give the first "Processing..." window time to pop up Local $hWnd1 = WinGetHandle("[REGEXPTITLE:(?i).*Processing.*?]") WinWaitNotActive($hWnd1, "",150) ; Timeout after 150 seconds - since that would mean there is an issue $hWnd1 = 0 ; reset window handle for next processing window If WinExists("[REGEXPTITLE:(?i).*Processing.*?]") Then Local $hWnd1 = WinGetHandle("[REGEXPTITLE:(?i).*Processing.*?]") WinWaitNotActive($hWnd1, "",150) EndIf $hWnd1 = 0 If WinExists("[REGEXPTITLE:(?i).*Processing.*?]") Then Local $hWnd1 = WinGetHandle("[REGEXPTITLE:(?i).*Processing.*?]") WinWaitNotActive($hWnd1, "",150) EndIf $hWnd1 = 0 If WinExists("[REGEXPTITLE:(?i).*Processing.*?]") Then Local $hWnd1 = WinGetHandle("[REGEXPTITLE:(?i).*Processing.*?]") WinWaitNotActive($hWnd1, "",150) EndIf Sleep(2000) MouseClick("right", 280, 174, 1, 20) Send("{DOWN 3}") Sleep(2000) Send("{RIGHT}") Sleep(2000) Send("{ENTER}") Sleep(2000) Send("{ESC}") Sleep(2000) ;all done I'm using Opt("WinTitleMatchMode", 1). I can find the window just fine when I'm not using WinExists(). Why doesn't this work after the PC upgrade and how do I fix it? Thanks for any help! Link to comment Share on other sites More sharing options...
Developers Jos Posted March 11, 2015 Developers Share Posted March 11, 2015 Is the running program or script shelled with elevated rights? (UAC) Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
JJohnson Posted March 12, 2015 Author Share Posted March 12, 2015 Is the running program or script shelled with elevated rights? (UAC) Jos I'm not sure. This is a fresh install of Win7. I looked at the properties of the exe that my script is running. It had "run as administrator" checked. I unchecked this and it didn't fix this issue. I then rechecked it along with setting WinXP compatibility and now my script won't even run the app. Odd. I've set it back to the way it was originally but it doesn't seem to want to run for my script anymore. Link to comment Share on other sites More sharing options...
JJohnson Posted March 12, 2015 Author Share Posted March 12, 2015 I just tested this: ShellExecute("c:FolderbinApp.exe","","c:Folderbin","",@SW_MAXIMIZE) and the app loads from an autoit script. My script doesn't do anything though once the app loads. I did something to this exe. Changing the "run as administrator" flag seems to have stopped the Run() function from working. Link to comment Share on other sites More sharing options...
JohnOne Posted March 12, 2015 Share Posted March 12, 2015 You need to add some debugging lines to your script. 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 More sharing options...
JJohnson Posted March 12, 2015 Author Share Posted March 12, 2015 After a reboot today the script loads the app normally and proceeds to the previous issue. I used MsgBox to return the handle of the window I'm trying to watch. There are 4 "Processing..." windows for each report I run. I need to wait until all 4 are finished before I perform a mouse click. This was working fine on my XP machine, but not on Win7. Using MsgBox I can see that it has trouble finding windows 2 and 4. Here is the code: Sleep(500) Local $hWnd1 = WinGetHandle("[REGEXPTITLE:(?i).*Processing.*?]") MsgBox("0", "Window1 Handle is", $hWnd1) WinWaitNotActive($hWnd1, "",150) $hWnd1 = 0 If WinExists("[REGEXPTITLE:(?i).*Processing.*?]") Then Local $hWnd1 = WinGetHandle("[REGEXPTITLE:(?i).*Processing.*?]") MsgBox("0", "Window2 Handle is", $hWnd1) WinWaitNotActive($hWnd1, "",150) Else MsgBox("0", "Nope", $hWnd1) EndIf $hWnd1 = 0 If WinExists("[REGEXPTITLE:(?i).*Processing.*?]") Then Local $hWnd1 = WinGetHandle("[REGEXPTITLE:(?i).*Processing.*?]") MsgBox("0", "Window3 Handle is", $hWnd1) WinWaitNotActive($hWnd1, "",150) Else MsgBox("0", "Nope", $hWnd1) EndIf $hWnd1 = 0 If WinExists("[REGEXPTITLE:(?i).*Processing.*?]") Then Local $hWnd1 = WinGetHandle("[REGEXPTITLE:(?i).*Processing.*?]") MsgBox("0", "Window4 Handle is", $hWnd1) WinWaitNotActive($hWnd1, "",150) Else MsgBox("0", "Nope", $hWnd1) EndIf Perhaps this is a timing issue of some sort? This is a much faster PC than my old one. It almost looks like the first If WinExists() code fires off before the window is there. So it returns "Nope 0" in the MsgBox. Perhaps my approach to this is wrong. Since I know there will always be 4 "Processing" windows should I use some other approach, or should I try using Sleep() after each WinExists? Link to comment Share on other sites More sharing options...
JJohnson Posted March 12, 2015 Author Share Posted March 12, 2015 Hmm I just tested some additional Sleep() functions in between each If WinExists() and it works. Seems the script is running faster on this new machine. I'd love not to have to do that. Should I change my process to WinWait or something? Link to comment Share on other sites More sharing options...
guinness Posted March 12, 2015 Share Posted March 12, 2015 My advice is always use WinWait(), especially if you're waiting for a process to start up. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now