SHDocVw::ShellWindows problem with vista
- From: Rohit Kumar <RohitKumar@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 9 Oct 2007 05:48:02 -0700
I am using the following piece of code to check whether there is an instance
of IE running on the system. It works fine for IE 6,7 on Xp. But on vista
this code doesnt seem to work. I am not able to create an instance of
SHDocVw::ShellWindows. It gives an ERROR_NO_TOKEN.
HRESULT hr;
UINT ieWindowCount = 0;
SHDocVw::IShellWindowsPtr spSHWinds;
hr = spSHWinds.CreateInstance
(__uuidof(SHDocVw::ShellWindows));
if (FAILED (hr))
{
return false;
}
long nCount = spSHWinds->GetCount(); // total number of explorer windows
IDispatchPtr spDisp;
// check whether its an explorer window or an IE window.
for (long i = 0; i < nCount; i++)
{
_variant_t va (i, VT_I4);
spDisp = spSHWinds->Item (va);
IWebBrowser2 * pWebBrowser = NULL;
hr = spDisp.QueryInterface (IID_IWebBrowser2, &
pWebBrowser);
if (pWebBrowser != NULL)
{
HRESULT hr;
IDispatch* pHtmlDocDispatch = NULL;
IHTMLDocument2 * pHtmlDoc = NULL;
// Retrieve the document object.
hr = pWebBrowser->get_Document (&pHtmlDocDispatch);
if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL))
{
// query for the html document's interface...
hr = pHtmlDocDispatch->QueryInterface
(IID_IHTMLDocument2, (void**)&pHtmlDoc);
if (SUCCEEDED (hr) && (pHtmlDoc != NULL))
{
ieWindowCount++;
if (ieWindowCount > 0)
return TRUE;
}
}
}
}
Can anyone please help me in this regard or suggest me a better way to find
if an instance of IE is running.
Thanks in advance
.
- Follow-Ups:
- Re: SHDocVw::ShellWindows problem with vista
- From: Sheng Jiang[MVP]
- Re: SHDocVw::ShellWindows problem with vista
- Prev by Date: Re: Igor's PassthroughAPP and VC8?
- Next by Date: Re: SHDocVw::ShellWindows problem with vista
- Previous by thread: Igor's PassthroughAPP and VC8?
- Next by thread: Re: SHDocVw::ShellWindows problem with vista
- Index(es):
Loading