Jump to content

execute _IECreate() with -nomerge parameter


Go to solution Solved by SmOke_N,

Recommended Posts

Hello,

I am looking for a way to use _IECreate() with the functionality to not share sessions, as it would be the case with running IE like "run(iexplore -nomerge)" <- simplified.

I am not looking for ways to attach to existing IE windows which are started by the run() command but rather looking for a way to either a) have that object modified to it uses the nomerge option or B) have the registry edited in such way to have IE com objects created with that switch by default.

I already tried the following. It works when launching IE from the start menu / the .exe file directly, but not when used as COM object:

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main]
"SessionMerging"=dword:00000000
"FrameMerging"=dword:00000000

 

Please note that the system I will use this on is dedicated for this scenario, so any possible alterations which might prevent "normal" IE activities are irrelevant here.

Link to comment
Share on other sites

  • Moderators

Doesn't seem that this has had a solution anywhere.

Just curious, since you can't modify the object after it's created in the way you want, but you can launch via Run() with the way you want... What's the problem with the solution that works exactly?

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Let's say you open a new IE instance with run() and then attach to it. How do you implement this "cleanly" without using Sleep() to just wait an arbitrary amount of time?

I'll post an example:

$run = Run('"C:\Program Files (x86)\Internet Explorer\iexplore.exe" -nomerge about:blank')

ProcessWait($run, 30)

;what if the process has not spawned a window yet?
$hWnd = _WinGetByPID($run)

;what if the window exists but is still being rendered - this might prevent functions like _IENavigate($oIE, $URL) from working immediately after the _IEAttach() function, or even make _IEAttach() not work properly itself.
WinWaitExist($hWnd, 30)

$oIE = _IEAttach($hWnd,"HWND")

;then continue to use the $oIE object to your liking

Func _WinGetByPID($iPID, $iArray = 1) ; 0 Will Return 1 Base Array & 1 Will Return The First Window.
    Local $aError[1] = [0], $aWinList, $sReturn
    If IsString($iPID) Then
        $iPID = ProcessExists($iPID)
    EndIf
    $aWinList = WinList()
    For $A = 1 To $aWinList[0][0]
        If WinGetProcess($aWinList[$A][1]) = $iPID And BitAND(WinGetState($aWinList[$A][1]), 2) Then
            If $iArray Then
                Return $aWinList[$A][1]
            EndIf
            $sReturn &= $aWinList[$A][1] & Chr(1)
        EndIf
    Next
    If $sReturn Then
        Return StringSplit(StringTrimRight($sReturn, 1), Chr(1))
    EndIf
    Return SetError(1, 0, $aError)
EndFunc   ;==>_WinGetByPID
Link to comment
Share on other sites

  • Moderators

I don't know, I'm sure you could find a way for it to be reliable ;)...

#include <IE.au3>

Global $goIE = _runIEObjCreate("http://autoitscript.com/forum", "-nomerge")

Func _runIEObjCreate($sURL, $sParams = "", $iTryAttach = 0, $iVisible = 1, $iWait = 1, $iTakeFocus = 1)

    Local Static $sHKCR = (@AutoItX64 ? "HKCR64" : "HKCR")
    Local Static $szCOMIE = FileGetShortName(RegRead($sHKCR & _
        "\CLSID\{0002DF01-0000-0000-C000-000000000046}\LocalServer32",""))
    
    ; comment out the above and uncomment the below if you need to test
;~  Local Static $szCOMIE = FileGetShortName(@HomeDrive & "\Program Files (x86)\Internet Explorer\iexplore.exe")

    ; get current shell windows open and their count
    Local $oShell = ObjCreate("Shell.Application")
    Local $oWin1 = $oShell.windows(), $oWin2
    Local $nCount = $oWin1.count()

    $sParams = (StringLen($sParams) > 0) ? " " & $sParams : ""

    Local $oRet, $iTimer = TimerInit() ; set a 5 minute timeout
    Local $iPID = Run($szCOMIE & $sParams)
    While 1
        $oWin2 = $oShell.windows()
        If $oWin2.count() <> $nCount Then
            $oRet = $oWin2($oWin2.count() - 1)
            If WinGetProcess($oRet.hwnd) = $iPID Then ExitLoop
        EndIf
        If (TimerDiff($iTimer) / 1000) >= 300 Then
            ; timed out waiting, close IE instance
            ProcessClose($iPID)
            Return SetError(1, 0, 0)
        EndIf
        Sleep(10)
    WEnd

    ; now nav to url
    _IENavigate($oRet, $sURL, $iWait)
    If @error Then
        Return SetError(2, @error, $oRet)
    EndIf

    Return $oRet
EndFunc 

I'm unsure if this will actually do the no merge... it may only be the IE you're running from Program Files (x86), you may need to replace my RegRead with a hard path.  I read the COM IE folder path specifically 

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Wow, impressive... thank you!

  Local Static $sHKCR = (@AutoItX64 ? "HKCR64" : "HKCR")

 

I never saw this usage of the "?" (question mark) before and can't find anything about it in the documentation. As far as I can tell it is a switch, as in "if AutoItX64 is used, go to HKCR64, else go to HKCR", correct? Is this documented somewhere?

I'm unsure if this will actually do the no merge... it may only be the IE you're running from Program Files (x86), you may need to replace my RegRead with a hard path.  I read the COM IE folder path specifically

 

That's fine, I am using this IE version anyways.

Link to comment
Share on other sites

  • Moderators
  • Solution

Checkout the phrase "ternary operator" in the help file.

Edit:

After looking at the above, I see a couple of things that need to change, so here is how I would run it.

#include <IE.au3>

Global $goIE = _runIEObjCreate("http://autoitscript.com/forum", "-noframemerging")

Func _runIEObjCreate($sURL, $sParams = "", $iTryAttach = 0, $iVisible = 1, $iWait = 1, $iTakeFocus = 1)

    Local Static $sHKCR = (@AutoItX64 ? "HKCR64" : "HKCR")
    Local Static $szCOMIE = FileGetShortName(RegRead($sHKCR & _
        "\CLSID\{0002DF01-0000-0000-C000-000000000046}\LocalServer32",""))

    ; get current shell windows open and their count
    Local $oShell = ObjCreate("Shell.Application")
    Local $oWin1 = $oShell.windows(), $oWin2
    Local $nCount = $oWin1.count()

    $sParams = (StringLen($sParams) > 0) ? " " & $sParams : ""

    Local $oRet, $iTimer = TimerInit() ; set a 5 minute timeout
    Local $iPID = Run($szCOMIE & $sParams & ' "' & $sURL & '"')
    While 1
        $oWin2 = $oShell.windows()
        If $oWin2.count() <> $nCount Then
            $oRet = $oWin2($oWin2.count() - 1)
            If WinGetProcess($oRet.hwnd) = $iPID Then ExitLoop
            $nCount = $oWin2.count()
        EndIf
        If (TimerDiff($iTimer) / 1000) >= 300 Then
            ; timed out waiting, close IE instance
            ProcessClose($iPID)
            Return SetError(1, 0, 0)
        EndIf
        Sleep(10)
    WEnd
    
    _IELoadWait($oRet)
    If @error Then
        Return SetError(2, @error, $oRet)
    EndIf

    Return $oRet
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Checkout the phrase "ternary operator" in the help file.

 

Thank you for the hint, I didn't know this syntax existed in AutoIt.

Edit:

After looking at the above, I see a couple of things that need to change, so here is how I would run it.

 

I already modified the navigate portion after you posted it but missed the $oWin2.count() part. However, you also changed the "-nomerge" switch to "-noframemerging" in the example. For people who read this: Internet Explorer up to the pre-release version of IE 8 uses the "-nomerge" switch, whereas this switch is superseeded by the "-noframemerging" switch starting with the release version of IE 8. The "-nomerge" switch is deprecated as of IE 10.

Edited by level20peon
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...