Create new session using _IECreate()

北城余情 提交于 2019-12-11 06:33:51

问题


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:


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


来源:https://stackoverflow.com/questions/42742964/create-new-session-using-iecreate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!