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
I think you need run the process as administrator or turn off UAC. -- Sheng Jiang Microsoft MVP in VC++ "Rohit Kumar" wrote in message news:09D0D835-B919-4AC0-931E-3B915D0628A9@microsoft.com... > 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 >