Sdi

Old Scenario: a COM object created inside a WSCRIPT file (javascript) used to CreateProcess() IE and then Navigate() the IWebBrowser2 object. Since MS has broken the contract on IWebBrowser2->Navigate(), we now have to call IELaunchURL().

New Scenario: same COM object calls IELaunchURL() and then enumerates the windows, looking for the IEFrame window in the process ID returned by IELaunchURL().

Problem: That process ID ("process A") is bogus. The IE instance matching the returned process ID runs for about a quarter of a second, and then a new IE process ("process B") starts up and the one returned by IELaunchURL() disappears. The requested URL is shown in process B, and process A no longer exists.

Ideas What is the process ID returned by IELaunchURL() supposed to be



Re: Internet Explorer Extension Development Bogus valus returned from IELaunchURL()

hao1st

Hi Sdi,

I met the same problem with you. Even worse, when I call IELaunchURL, I got the error code 87. Can you please show me the code sample how you can call IELaunchURL successfully

Thanks,
Hao




Re: Internet Explorer Extension Development Bogus valus returned from IELaunchURL()

Sdi

IELaunchURL() seems completely broken. As mentioned, even when it works, it lies about what it did. And it seems to be willing to fail at the drop of a hat, and with undocumented error codes: I can get it to fail with ERROR_INVALID_PARAMETER or ERROR_ACCESS_DENIED just by changing the URL or by including/omitting the IELAUNCHURLINFO parameter. Which parameter seems completely useless for anyone except a debugger; I just pass NULL.





Re: Internet Explorer Extension Development Bogus valus returned from IELaunchURL()

Reza Nourai - MSFT

How are you using IELaunchURL It works fine any way I try it.

Code Snippet

PROCESS_INFORMATION piIE;

HRESULT hr = IELaunchURL(L"http://www.live.com", &piIE, NULL);

if (SUCCEEDED(hr))

{

TerminateProcess(piIE.hProcess,0);

CloseHandle(piIE.hThread);

CloseHandle(piIE.hProcess);

wprintf(L"Success!");

}

else

{

wprintf(L"Failed with hr = 0x%x", hr);

}

-Reza





Re: Internet Explorer Extension Development Bogus valus returned from IELaunchURL()

Reza Nourai - MSFT

Maybe this is a better example:

Code Snippet

#include <windows.h>

#include <atlbase.h>

#include <exdisp.h>

#include <iepmapi.h>

#include <stdio.h>

#import <shdocvw.dll>

HRESULT GetIWebBrowser2(DWORD dwProcId, IWebBrowser2** ppBrowser);

void wmain()

{

PROCESS_INFORMATION piIE;

DWORD dwIEProc = 0;

IWebBrowser2* pWB2 = NULL;

CoCreateInstance(NULL);

HRESULT hr = IELaunchURL(L"http://www.live.com", &piIE, NULL);

if (SUCCEEDED(hr))

{

WaitForInputIdle(piIE.hProcess,3000);

dwIEProc = piIE.dwProcessId;

CloseHandle(piIE.hThread);

CloseHandle(piIE.hProcess);

}

else

{

wprintf(L"Failed with hr = 0x%x\n", hr);

exit(1);

}

hr = GetIWebBrowser2(dwIEProc,&pWB2);

if (SUCCEEDED(hr))

{

CComVariant vUrl(L"http://www.msn.com");

VARIANT vEmpty = {0};

pWB2->Navigate2(&vUrl,&vEmpty,&vEmpty,&vEmpty,&vEmpty);

pWB2->Release();

pWB2 = NULL;

}

CoUninitialize();

}

With the code for GetIWebBrowser2 looking something like this:

Code Snippet

HRESULT GetIWebBrowser2(DWORD dwProcId, IWebBrowser2** ppBrowser)

{

HRESULT hr = E_FAIL;

*ppBrowser = NULL;

SHDocVw::IShellWindowsPtr spSHW;

CComPtr<IDispatch> spDisp;

spSHW.CreateInstance(__uuidof(SHDocVw::ShellWindows));

long nCount = spSHW->GetCount();

for (long i=0; i<nCount; i++)

{

CComVariant v(i, VT_I4);

spDisp = spSHW->Item(v);

hr = spDisp->QueryInterface(IID_IWebBrowser2,(void**)ppBrowser);

if (SUCCEEDED(hr) && (*ppBrowser) != NULL)

{

LONG_PTR hwndIE;

(*ppBrowser)->get_HWND(&hwndIE);

DWORD dwProc = 0;

DWORD dwThread = GetWindowThreadProcessId((HWND)hwndIE,&dwProc);

if (dwProc == dwProcId)

{

hr = S_OK;

break;

}

else

{

hr = E_FAIL;

(*ppBrowser)->Release();

*ppBrowser = NULL;

}

}

}

return hr;

}

-Reza





Re: Internet Explorer Extension Development Bogus valus returned from IELaunchURL()

Reza Nourai - MSFT

The only potential for this failing is if you hit the GetIWebBrowser2 call too soon after the IELaunchURL. If you put in a sleep statement (just for testing purposes) after WaitForInputIdle, then this will work flawlessly every time.

-Reza





Re: Internet Explorer Extension Development Bogus valus returned from IELaunchURL()

Sdi

Thanks, but that's what we already do (except you don't want to just Sleep; you use WaitForInputIdle). As stated, the problem is that the process ID returned by IELaunchURL ("dwIEProc" in your code) is NOT the instance of IE that shows the requested URL; it is the instance of IE that runs for a few milliseconds before yet another IE instance opens, and that last one is the one that shows the URL; the IE process "dwIEProc" is gone.



Re: Internet Explorer Extension Development Bogus valus returned from IELaunchURL()

Reza Nourai - MSFT

The process ID I am getting back is the process id of the browser. I am running the application above and it is working just fine. Are you running your app as admin Running as admin breaks IELaunchURL just so you know.

-Reza

PS. I know the sleep is not what you want to do, I was only mentioning it as a way to debug. And WaitForInputIdle IS NOT long enough to wait. This may be why you are not able to access the right Process ID. If everything else in your code seems right, just put a sleep in for debugging purposes and see if it fixes it.





Re: Internet Explorer Extension Development Bogus valus returned from IELaunchURL()

Sdi

Sorry, I should have been more clear; the sequence is WaitForInputIdle/EnumWindows/break if found/short Sleep(), all inside a while() loop. But that has nothing to do with "not able to access the right process ID", because that isn't the problem.

No, this is not running as admin.

The failure happens when the URL requires an IL that doesn't match that of the calling process. For example, if I have a script running in a low-IL protected-mode IE that needs to open an URL that is in Trusted Sites (I don't control whether or not the users put any arbitrary site into their Trusted Sites) and then manipulate that URL, my app breaks: my script creates a new IE instance, but when I call Navigate, I lose control, because the navigation happens in a new IE instance that I don't know about (even though Navigate returned S_OK). So I try to use IELaunchURL. But that function also lies; the process ID returned is not the process ID of the non-protected-mode Trusted Site IE instance that actually shows the URL; it is of a short-lived (probably protected mode, but I don't know because it disappears immediately) IE instance, and again the URL opens in a non-protected-mode Trusted Site IE instance that I know nothing about. I already know that the URL is not a protected-mode URL; if IELaunchURL returned accurate information, I could call out to my medium-IL broker process with the process ID returned by IELaunchURL and have it do the post-navigation manipulation of the Trusted-Site IE instance. But the process ID that IELaunchURL gave me is bogus; it is already gone.





Re: Internet Explorer Extension Development Bogus valus returned from IELaunchURL()

VladS

Hello Sdi,

You may try CreateToolhelp32Snapshot(), Process32First(), Process32Next().

PROCESSENTRY32 contains th32ParentProcessID (process's parent process).

It's most likely the process that starts the second IE instance.

I did not try this, so i wonder if it helps...

I have E_INVALIDARG ret code from IELaunchURL(L"about:blank"), don't have solution at the moment.

Vlad





Re: Internet Explorer Extension Development Bogus valus returned from IELaunchURL()

Sdi

Thanks; yeah, I know a couple of ways around the problem, but they don't relieve MS of its responsibility to either stop breaking a published interface that people have been relying on for a decade, or to provide us an alternative that works as advertised.



Re: Internet Explorer Extension Development Bogus valus returned from IELaunchURL()

Reza Nourai - MSFT

I am still not sure what could be going wrong. I can't reproduce your problem here. I am getting the right process ID back every time.

-Reza





Re: Internet Explorer Extension Development Bogus valus returned from IELaunchURL()

Ishay Sivan

IELaunchURL() returnes different values depending on the integrity level it is run from.

It probably trying to determen if the proccess integrity level permits it to run IE that will go to that URL.

For example, if it is a trusted site and your proccess is in low integrity level, the function fails.

IELaunchURL(L"about:blank"), always retuns "invalid arg" for some reason. maybe the code there can't figure out the integrity level needed for that URL.





Re: Internet Explorer Extension Development Bogus valus returned from IELaunchURL()

shri_1001

Hey I've been struggling to work aroung the problem of bogus IDs. Can anyone here suggest some solution



Re: Internet Explorer Extension Development Bogus valus returned from IELaunchURL()

PraveenM [MSFT]

about:blank is like a neutral url (does not map to protected mode) so that is why you are getting a E_INVALIDARG.

One way to do this is

I dont think you can use Process Info struct the documentation says you should use IELaunchURLInfo

IELAUNCHURLINFO launchInfo;
launchInfo.cbSize = sizeof(IELAUNCHURLINFO);
launchInfo.dwCreationFlags = NULL;

If (IEIsProtectedModeURL(szURL))

{

IELaunchURL(szURL, &launchInfo, NULL)

}

else

{

// CoCreateInstance(CLSID_InternetExplorer);

}

Praveen