pilky1986 Posted October 12, 2011 Share Posted October 12, 2011 (edited) #include <IE.au3> Dim $IE_WINDOW_HANDLE_TEMP = WinGetHandle("[Class:IEFrame]") Dim $IE_WINDOW_HANDLE = String($IE_WINDOW_HANDLE_TEMP) MsgBox(0,"WINDOW HANDLE",$IE_WINDOW_HANDLE) $URL = _IEAttach($IE_WINDOW_HANDLE,"title","") MsgBox(0,"",$URL) #include <IE.au3> Dim $IE_WINDOW_HANDLE_TEMP = WinGetHandle("[Class:IEFrame]") Dim $IE_WINDOW_HANDLE = String($IE_WINDOW_HANDLE_TEMP) MsgBox(0,"WINDOW HANDLE",$IE_WINDOW_HANDLE) $URL = _IEPropertyGet($IE_WINDOW_HANDLE,"locationurl") MsgBox(0,"",$URL) If i use the above code (ran separately) the value that is returned is 0 i.e. an error for _IEAttach is error code 5 ($_IEStatus_InvalidValue) = Invalid Value for _IEPropertyGet its error code 3 ($_IEStatus_InvalidDataType) = Invalid Data Type The handle of the IE window is returned correctly.. FYI: I am using Internet Explorer v 8.0.6001.18702 Can any one point me in the right direction please? Edited October 12, 2011 by pilky1986 Link to comment Share on other sites More sharing options...
jaberwacky Posted October 13, 2011 Share Posted October 13, 2011 Try this: #include <IE.au3> Dim $IE_WINDOW_HANDLE_TEMP = WinGetHandle("[Class:IEFrame]") Dim $IE_WINDOW_HANDLE = String($IE_WINDOW_HANDLE_TEMP) MsgBox(0, "WINDOW HANDLE", $IE_WINDOW_HANDLE) $URL = _IEAttach($IE_WINDOW_HANDLE, "title", "") MsgBox(0, "", $URL) $URL = _IEPropertyGet($IE_WINDOW_HANDLE, "locationurl") MsgBox(0, "", $URL) I removed the duplicate lines. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
pilky1986 Posted October 13, 2011 Author Share Posted October 13, 2011 LaCastiglione, thank you for the response. I was running them as separate scripts that's why there was duplicates, i should of separated them to make that clearer. Sorry :-) However, it still does not work with that code.. The function correctly gathers the HWND (Handle of IE Window) but when it is passed to the function to get the url these functions do not work.. I wonder if they are compatible with IE8... any ideas any one? Link to comment Share on other sites More sharing options...
jaberwacky Posted October 15, 2011 Share Posted October 15, 2011 I just now saw this in the helpfile: _IEAttach ( $s_string [, $s_mode = "Title" [, $i_instance = 1]] ) $i_instance: "1-based index into group of browsers or embedded browsers matching $s_string and $s_mode." $URL = _IEAttach($IE_WINDOW_HANDLE, "title", "") You have it set to "". I don't know if it matters. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
DaleHohm Posted October 19, 2011 Share Posted October 19, 2011 You are not passing the right types of parametersto those functions. Please go back and examine the documentation, Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
pilky1986 Posted October 19, 2011 Author Share Posted October 19, 2011 Well how silly do I now feel!! #include <IE.au3> Dim $IE_WINDOW_HANDLE_TEMP = WinGetHandle("[Class:IEFrame]") Dim $IE_WINDOW_HANDLE = String($IE_WINDOW_HANDLE_TEMP) $oIE = _IEAttach ($IE_WINDOW_HANDLE,"HWND") MsgBox(0, "The URL", _IEPropertyGet ($oIE, "locationurl")) The above code returns the url of the Internet Explorer.. thanks for your help guys.. However, I have just noticed that it only returns the URL of the first tab regardless of which tab is currently active and what is displayed in the address bar... Any tips/hints? Link to comment Share on other sites More sharing options...
pilky1986 Posted October 19, 2011 Author Share Posted October 19, 2011 (edited) I think i have found my answer here.. Edit: DaleHohm: Is it possible to get the url of the active tab? Im not asking for you to give me the code.. but either a yes/no or a hint on where to look. Thanks in advance :-) Edited October 19, 2011 by pilky1986 Link to comment Share on other sites More sharing options...
DaleHohm Posted October 19, 2011 Share Posted October 19, 2011 Using the methods in the post you incuded bove, yes, along with _IEPropertyGet locationurl Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
pilky1986 Posted October 27, 2011 Author Share Posted October 27, 2011 (edited) DaleHohm: Thank you for all your input. I have finally achieved my goal. I have attached the script if people would like to use it. It checks all current tabs and then closes internet explorer if a blocked website is found (uses a definition file) expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=close.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstants.au3> #Include <File.au3> #Include <Array.au3> #include <Misc.au3> #include <IE.au3> ;************************************************************************************************************************************************************************* ; Version Information ;************************************************************************************************************************************************************************* ; Version 1.2 ;************************************************************************************************************************************************************************* ; System Tray Options ;************************************************************************************************************************************************************************* TraySetIcon(1) ; Creates/Enables a tray icon for the program TraySetClick(0) ;Stops the tray icon from being clicked on TraySetToolTip("v1.2") ;When the mouse hovers over the tray icon it displays the text ;************************************************************************************************************************************************************************* ; Variables and Constants Declerations ;************************************************************************************************************************************************************************* dim $blocked dim $i dim $i2 dim $call = 0 dim $refresh_timer = 0 dim $aIE ;dim const $blocklistlocation = "\\Barnts01\programs$\programs\block list.txt" ; Writes the location of the keyword file to memory ;dim const $TabClosePromptTitle = FileOpen("\\Barnts01\programs$\programs\tab close prompt title.txt") ;sets the location and opens the file for the string for the tab close prompt window title dim const $blocklistlocation = ".\block list.txt" ; Writes the location of the keyword file to memory dim const $TabClosePromptTitle = FileOpen(".\tab close prompt title.txt") ;sets the location and opens the file for the string for the tab close prompt window title dim const $TabClosePromptTitleDataCitrix = FileReadLine($TabClosePromptTitle,1) ;gets the tab close prompt window title data (string) from the file - line 1 dim const $TabClosePromptTitleDataIE = FileReadLine($TabClosePromptTitle,2) ;gets the tab close prompt window title data (string) from the file - line 2 ;************************************************************************************************************************************************************************* ; Load the list of keywords from the block list.txt file to memory (array) ;************************************************************************************************************************************************************************* _FileReadToArray($blocklistlocation,$blocked) ;Reads the block list text file to memory (array) ;************************************************************************************************************************************************************************* ; Functions ;************************************************************************************************************************************************************************* Func _Check_Tab_Close() ; This function checks if the internet explorer multiple tab close window is present. If it is present it clicks the close all button AutoItSetOption("WinTitleMatchMode", 3) ; Used so that when WinExists below is used it searches exactly for the mentioned text only If WinExists($TabClosePromptTitleDataCitrix) or WinExists($TabClosePromptTitleDataIE) Then ; Checks to see if a window exists with the mentioned text Send("{ENTER}") ;Presses (sends) the Enter/Return key EndIf Sleep(2000) ;Pauses the program for 2 seconds i.e. keeps the message on screen for that length of time SplashOff() ; Turns off the on screen message created above $call = 0 ; Sets the $call variable back to 0 .. see _Win_Close function for variable being set to 1 EndFunc Func _Win_Close() ; Used to check the IE window URL(s) (single or multi-tab) against a list. If a match is found the IE window is closed. Dim $aIE[1] ; Creates a space in memory for an array $aIE[0] = 0 ; Sets the number of elements in the array to 0 $i = 1 While 1 ; starts a loop for collecting the URL(s) of IE $oIE = _IEAttach ("", "instance", $i) If @error = $_IEStatus_NoMatch Then ExitLoop ReDim $aIE[$i + 1] $aIE[$i] = _IEPropertyGet($oIE, "locationurl") $aIE[0] = $i $i += 1 WEnd ; ends the loop AutoItSetOption("WinTitleMatchMode", 2) ;Sets the searching options for WinClose to search the windows title (set to find X anywhere in string) ; Checks the array $aIE populated from the first above While statement agasint the $blocked array (block list entries) and closes IE if a match is found For $i = 1 To (UBound($aIE) - 1) For $i2 = 1 To (UBound($blocked) - 1) If StringInStr($aIE[$i],$blocked[$i2]) <> 0 Then SplashTextOn("Website Blocker","WEBSITE BLOCKED" & @CRLF & @CRLF & "Access to this site is prohibited!",400,100,-1,-1,33,"",15,900) ; creates a message on screen WinClose("[Class:IEFrame]") ;Closes any windows with any of the keywords contained within block list.txt in the windows title dim $call = 1 ; sets the $call variable to 1, this is used to see if _Check_Tab_Close function needs to be called EndIf Next Next if $call = 1 then ; Checks if $call variable is equal to 1 i.e. check if the _Check_Tab_Close function needs to be called call ("_Check_Tab_Close") ;Calls the function _Check_Tab_Close Endif EndFunc Func _Refresh_Block_List() _FileReadToArray($blocklistlocation,$blocked) ;Reads the block list text file to memory (array) $refresh_timer = 0 ;Sets the timer varaible back to 0 so that the re-counting process can start again EndFunc ;************************************************************************************************************************************************************************* ; Program Loop (Program in effect starts here) ;************************************************************************************************************************************************************************* While 1 ;creates an infinite loop If WinExists("[Class:IEFrame]") Then call ("_Win_Close") ;call the function _Win_Close Endif Sleep(1000) ;Pauses the program for 1 second - Used so it does not cause CPU to max out at 100% $refresh_timer +=1 ;Adds one to the value of the varaibale every time the while loop runs (runs every second) therefore the timer counts up in seconds If $refresh_timer = 1800 Then ; When the timer gets to 1800 seconds (30 minutes) then the function for refreshing the block list is called Call ("_Refresh_Block_List") ; Calls the function _Refresh_Block_List to refresh the block list file EndIf WEnd I still need to work on it. Every time the _Win_Close function is called the cpu load spikes. I know why (because the function is called) but i would like to try to find a more efficient way. When lots of tabs are open (a ridiculous amount) cpu spikes hit around 20% (but only briefly) so its not killing the computer but its not great either. Any suggestions/improvements or more efficient way of doing this.. then please feel free to post :-) I was considering just closing the tab its self but It does what i need it to do so for the time being it shall sufice. Edited October 27, 2011 by pilky1986 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