Create new session using _IECreate()

2019-07-28 17:50发布

I have two AutoIt scripts. Both contain Global $oIE = _IECreate($myUrl, 1). They create two IE windows for the same URL.

In IE, when selecting "new session" from "file" menu, each window gets its own session. But using two different script files at the same time, both windows login to the same account. How can I open every IE window with a new session?

1条回答
甜甜的少女心
2楼-- · 2019-07-28 18:10

Sessions relate to each unique iexplore.exe process. Start new instance of iexplore.exe per required session (untested, no error checking) :

#include <IE.au3>

Global Const $g_sUrl = 'https://stackoverflow.com/'
Global       $g_aIE[2]

For $i1 = 0 To UBound($g_aIE, 1) -1    
    _IECreateSession($g_aIE[$i1], $g_sUrl)    
Next

Func _IECreateSession(ByRef $oIE, Const $sUrl)
    Local Const $iPID = ShellExecute('iexplore.exe', '-nosessionmerging about:blank')
    Local       $aWnd

    WinWait('Blank Page')       
    $aWnd = _WinAPI_EnumProcessWindows($iPID, True)
    $oIE  = _IEAttach($aWnd[1][1], 'hwnd')    
    _IELoadWait($oIE)
    _IENavigate($oIE, $sUrl)

    Return $iPID    
EndFunc
查看更多
登录 后发表回答