Jump to content

Internet Explorer private browsing with _IE UDF


Recommended Posts

Hi all,

I'm looking for a way to enable private borwsing in my embedded IE object, created with _IECreateEmbedded.

So far I can only imagine 3 solutions :

1. Start an IE process with the "-private" switch

That's not what I'm looking for as it would create an independant IE. I insist that this one must be embedded.

EDIT: actually I've found out that this can used with the other switch "-embedding" that is then supposed to make the IE window embeddable as an OLE object. but I don't know how to do that!

2. Simulate "Shift+Ctrl+P"

I'm not sure it would work in an embedded IE. I've tested manually, but it doesn't do anything. But maybe it's simply because the keys combination is passed to the Autoit window, and not forwarded to the IE object. I don't know.

I don't know what command I should use to pass a keystroke to an embedded IE object.

3. Use a clean COM message to enable Inprivate browsing

I'm not good enough to know how to do that. If anybody has a suggestion...

In a more general manner, I want to be sure that everything I do with IE in my script stays in my script (I don't want the browsing history of my script to interfere with the user's)

Edited by MonsieurOUXX
Link to comment
Share on other sites

I'd suggest a Google search for webbrowser control inprivate

I don't think this is possble.

Perhaps explore the "alternative to _IECreateEmbedded" in my sig.

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

Thank you Dale.

I had seen that thread, but I had failed to spot that this custom function runs Internet Explorer via the command line.

In theory, that would instantly solve my issue (as all I have to do is to add the "-private" command).

Here is a copy-paste of the thread you mention :

Func _IECreateEmbed2($xWidth, $xHeight, $iX, $iY, $hGUI)    
    $pID = Run(@ProgramFilesDir & "\internet explorer\iexplore.exe -k " & $sURL, "", @SW_HIDE)  
    Do      
        Sleep(100)  
    Until Not (ProcessExists($pID) = 0)  
    
    $hHandle = _ProcessGetHWnd($pID)
    
    Do      
        $oIElocal = _IEAttach($hHandle, "HWND")
        Sleep(100)
    Until $oIElocal <> 0
    GUISetState(@SW_SHOW, $hGUI)
    _WinAPI_SetParent($hHandle, $hGUI)
    _WinAPI_MoveWindow($hHandle, $iX, $iY, $xWidth, $xHeight, True)
    _WinAPI_SetWindowLong($hHandle, $GWL_STYLE, BitOR($WS_CHILD, $WS_VISIBLE))
    
    Return $oIElocal
EndFunc;==>_IECreate2
 
Func _ProcessGetHWnd($iPid, $sTitle = "", $iTimeout = 2000)
     Local $aWin
     While 1
        $aWin = WinList($sTitle)
        For $i = 1 To $aWin[0][0]
        If $iPid = WinGetProcess($aWin[$i][1]) Then
            Return $aWin[$i][1]
        EndIf
        Next
    
    Sleep(500) ; add a timer here
    WEnd
    SetError(1)
    Return 0
EndFunc   ;==>_ProcessGetHWnd

...But for some mysterious reason, as soon as I change "-k" to "-private", then:

  • _ProcessGetHWnd fails to find the hwnd for the pid returned by "Run"
  • Internally, it's WinList that returns a list that does not contain the new pid..
  • I've use an alternative version of the function searching the hwnd from the pid (see below)
  • That function does return an hwnd, but then it's _IEAttach that fails with that hwnd, with error "Warning from function _IEAttach, $_IEStatus_NoMatch"

Could someone who has knowledge of Win32 explain :

  • Why the original _ProcessGetHWnd does not find an hwnd when IE is started with "-private" ?
  • Why the alternative _GetHwndFromPID finds a hwnd, but then _IEAttach fails to use it ?

Thanks for your help guys, it would be about time Autoit could use the Private Browsing.

The alternative function:

Func _GetHwndFromPID($PID)
    $hWnd = 0
    $stPID = DllStructCreate("int")
    Do
        $winlist2 = WinList()
        For $i = 1 To $winlist2[0][0]
            If $winlist2[$i][0] <> "" Then
                DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID))
                If DllStructGetData($stPID, 1) = $PID Then
                    $hWnd = $winlist2[$i][1]
                    ExitLoop
                EndIf
            EndIf
        Next
        Sleep(100)
    Until $hWnd <> 0
    Return $hWnd
EndFunc ;==>_GetHwndFromPID
Edited by MonsieurOUXX
Link to comment
Share on other sites

IT WORKS!

I'm not sure exactly what I changed, but it works.

However, when using -k additionally to -private, the symptoms described above remain.

That means with my current solution you can't use private browsing while in "kiosk" mode. (kiosk mode = when the address bar and other buttons are hidden)

I'll post the code asap

Link to comment
Share on other sites

Here is the final code :

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#include "IE3.au3"
 
Local $pid, $hHandle, $hGUI, $sURL, $xHeight, $xWidth
$sURL = "www.google.com"
$xWidth = 800
$xHeight = 600
 
$hGUI = GUICreate("Test", $xWidth, $xHeight)
$oIE = _IECreateEmbed2(500, 500, 10, 10, $hGUI)
_IENavigate($oIE, "www.google.com")
 
 
 
Func _IECreateEmbed2($xWidth, $xHeight, $iX, $iY, $hGUI)    
    $pID = Run(@ProgramFilesDir & "\internet explorer\iexplore.exe -private " & $sURL, "", @SW_HIDE)    
    Do      
        Sleep(100)  
    Until Not (ProcessExists($pID) = 0)  
        
    $hHandle = _ProcessGetHWnd($pID)
 
    Do      
        $oIElocal = _IEAttach($hHandle, "HWND")
        Sleep(100)
    Until $oIElocal <> 0
    
    GUISetState(@SW_SHOW, $hGUI)
    _WinAPI_SetParent($hHandle, $hGUI)
    _WinAPI_MoveWindow($hHandle, $iX, $iY, $xWidth, $xHeight, True)
    _WinAPI_SetWindowLong($hHandle, $GWL_STYLE, BitOR($WS_CHILD, $WS_VISIBLE))
    
    Return $oIElocal
EndFunc;==>_IECreate2
 
 
Func _ProcessGetHWnd($iPid, $sTitle = "", $iTimeout = 2000)
     Local $aWin
     While 1
        $aWin = WinList($sTitle)
        For $i = 1 To $aWin[0][0]
        If $iPid = WinGetProcess($aWin[$i][1]) Then
            Return $aWin[$i][1]
        EndIf
        Next
    
    Sleep(500) ; add a timer here
    WEnd
    SetError(1)
    Return 0
EndFunc   ;==>_ProcessGetHWnd
 
Do
    Sleep(50)
Until GUIGetMsg() = $GUI_EVENT_CLOSE
 
 
_IEQuit($oIE)
Sleep(500) ;alternatively: use "ProcessClose" using the pid returned earlier by "Run". Or iterate on "Processexists" using the same Pid, until Processexists returns 0

For more variations on these functions, see the thread where they were designed: #712594

  • Basically, all I did was replace the "-k" switch with the "-private" switch
  • VERY IMPORTANT: Do not set $sURL to "about:blank" otherwise The functions fail to find the hwnd of the Browser instance stared with "Run". I suppose IE does not create a window until it has an actual URL, or something like that.
Edited by MonsieurOUXX
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...