JJohnson

Switched from XP to Win7 - WinExists stops working?

8 posts in this topic

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!

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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.  

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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? 

Share this post


Link to post
Share on other sites

My advice is always use WinWait(), especially if you're waiting for a process to start up.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

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