Yodavish Posted February 18, 2020 Share Posted February 18, 2020 (edited) I have this AutoIt script executable in the Windows 10 startup folder, along with 3 other things in the startup folder: Internet Explorer (IE ) to a specific webpage, 3rd party application for the client to use, and another AutoIt script. Once a user logs into Windows, one of the many tasks the AutoIt script will do is a loop to check if the specific IE title exists and move it to the secondary monitor, however, it always fails. Either, it doesn't move it at all or I see a gray blank IE page on the secondary monitor. This only occurs on the first login, if I close the AutoIt.exe down and re-run the AutoIt.exe again it will then move the IE over correctly. Other things I've tried so far but have failed: Tested different times to delay, sleep(10000), before the script goes into the while Adding a RunWait() to open up the specific page in question first before the while Here is specific code in question, I can add the whole thing if needed: expandcollapse popupGlobal Const $proTrackerWindowTitle = IniRead("gross.ini", "default", "proTrackerWindowTitle", "NONE") ; The title of ProTracker window Global $proTrackerMovedFlag = '' While 1 ;---------------------------------------------------------- ; Moves IE Window to secondary monitor only once ; $proTrackerMovedFlag = '' is the one time trigger ;---------------------------------------------------------- If WinExists($proTrackerWindowTitle) and $proTrackerMovedFlag = '' Then moveProTrackerWindow() EndIF Sleep(100) ; Sleep to reduce CPU usage WEnd ;--------------------------------------------------------------- ; Functions ;--------------------------------------------------------------- Func moveProTrackerWindow() Local $aPos, $aData = _WinAPI_EnumDisplayMonitors() If IsArray($aData) Then ReDim $aData[$aData[0][0] + 1][5] For $i = 1 To $aData[0][0] $aPos = _WinAPI_GetPosFromRect($aData[$i][1]) If($aPos[0] <> 0) Then For $j = 0 To 3 Switch $j Case 0 ; index for X-position of secondary monitor $secondMonitorPosition = $aPos[$j] Case 2 ; index for width of secondary monitor $secondMonitorWidth = $aPos[$j] Case 3 ; index for height of secondary monitor $secondMonitorHeight = $aPos[$j] EndSwitch Next EndIf Next EndIf $hWnd=WinActivate($proTrackerWindowTitle) ; Checks to see if proTracker is maximized If BitAND(WinGetState($hWnd), 32) Then ;consoleWrite ("Maximized" & @CRLF) ; Gets proTracker position Local $aPos = WinGetPos ($proTrackerWindowTitle) ;consoleWrite ("Pos: " & $aPos[0] & @CRLF) ; Checks if the position is at the second monitor If $aPos[0] <> $secondMonitorPosition Then ;consoleWrite ("Maximized but position is wrong" & @CRLF) WinMove($hWnd, "", $secondMonitorPosition, 0,$secondMonitorWidth, $secondMonitorHeight) WinWait($hWnd) WinSetState($hWnd, "", @SW_MAXIMIZE) EndIf Else ;consoleWrite ("Not Maximized" & @CRLF) WinMove($hWnd, "", $secondMonitorPosition, 0, $secondMonitorWidth, $secondMonitorHeight) WinWait($hWnd) WinSetState($hWnd, "", @SW_MAXIMIZE) EndIf $proTrackerMovedFlag = True ;_ArrayDisplay($aData, '_WinAPI_EnumDisplayMonitors') ; displays monitor numbers consoleWrite("Width: " & $secondMonitorWidth & " Height: " & $secondMonitorHeight & " Second Monitor Position: " & $secondMonitorPosition & @CRLF) EndFunc Edited February 18, 2020 by Yodavish wording Link to comment Share on other sites More sharing options...
Nine Posted February 18, 2020 Share Posted February 18, 2020 (edited) Tested on single monitor (win 10), compiled x86, made a shortcut in startup folder. Working : #include <Constants.au3> #include <IE.au3> Local $oIE = _IECreate ("google.ca") Local $hWnd = _IEPropertyGet ($oIE, "hwnd") WinMove ($hWnd, "", 100, 100, 800, 600) Sleep (3000) WinSetState ($hWnd, "", @SW_MAXIMIZE) Sleep (1000) Edited February 18, 2020 by Nine not menu but folder, I meant Yodavish 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Yodavish Posted February 18, 2020 Author Share Posted February 18, 2020 Thanks @Nine I tried your suggestion and that lead me to see that the issue was due to the fact that _IECreate has issues with creating intranet addresses. So I modified the code and I think it works now, but I'll continue to test it. Adjust code below: expandcollapse popupFunc moveProTrackerWindow() ; Code below was copied from AutoIt Help by searching "_WinAPI_EnumDisplayMonitors" and altered slightly Local $aPos, $aData = _WinAPI_EnumDisplayMonitors() If IsArray($aData) Then ReDim $aData[$aData[0][0] + 1][5] For $i = 1 To $aData[0][0] $aPos = _WinAPI_GetPosFromRect($aData[$i][1]) If($aPos[0] <> 0) Then For $j = 0 To 3 Switch $j Case 0 ; index for X-position of secondary monitor $secondMonitorPosition = $aPos[$j] Case 2 ; index for width of secondary monitor $secondMonitorWidth = $aPos[$j] Case 3 ; index for height of secondary monitor $secondMonitorHeight = $aPos[$j] EndSwitch Next EndIf Next EndIf ;WinActivate($proTrackerWindowTitle) ShellExecute("iexplore.exe", "about:blank") sleep(3000) $oIE = _IEAttach("about:blank", "url") _IENavigate($oIE, "intranet URL address") Local $hWnd = _IEPropertyGet($oIE, "hwnd") ; Checks to see if proTracker is maximized If BitAND(WinGetState($hWnd), 32) Then ;consoleWrite ("Maximized" & @CRLF) ; Gets proTracker position Local $aPos = WinGetPos($hWnd) ;consoleWrite ("Pos: " & $aPos[0] & @CRLF) ; Checks if the position is at the second monitor If $aPos[0] <> $secondMonitorPosition Then ;consoleWrite ("Maximized but position is wrong" & @CRLF) WinMove($hWnd, "", $secondMonitorPosition, 0,$secondMonitorWidth, $secondMonitorHeight) WinWait($hWnd) WinSetState($hWnd, "", @SW_MAXIMIZE) EndIf Else ;consoleWrite ("Not Maximized" & @CRLF) WinMove($proTrackerWindowTitle, "", $secondMonitorPosition, 0, $secondMonitorWidth, $secondMonitorHeight) WinWait($hWnd) WinSetState($hWnd, "", @SW_MAXIMIZE) EndIf $proTrackerMovedFlag = True ;_ArrayDisplay($aData, '_WinAPI_EnumDisplayMonitors') ; displays monitor numbers consoleWrite("Width: " & $secondMonitorWidth & " Height: " & $secondMonitorHeight & " Second Monitor Position: " & $secondMonitorPosition & @CRLF) EndFunc 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