System.Runtime.InteropServices.COMException

shdxiang 2010-02-27 11:01:36

//捕获IE窗口
private void webBrowser1_NewWindow(object sender, CancelEventArgs e)
{
WriteLog("捕获默认IE窗口");
timeIE.Enabled = true;
timeIE.Start();
}
private void timeIE_Tick(object sender, EventArgs e)
{

ListenIE();
}
private void ListenIE()
{
try
{
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();

mshtml.IHTMLDocument2 htmlDoc;

String filename = null;
String str = null;

foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filename.Equals("iexplore"))
{
//Console.WriteLine(ie.LocationURL);
htmlDoc = ie.Document as mshtml.IHTMLDocument2;
//System.Threading.Thread.Sleep(3000);
IntPtr activeHwnd = GetForegroundWindow();
//Console.WriteLine("activeHwnd====" + activeHwnd);
WriteLog("--------------");
if (htmlDoc != null)
{
if (ie.HWND == activeHwnd.ToInt32())
{
ie.Refresh();
}
try
{
str = htmlDoc.body.innerHTML;

//Console.WriteLine("=========>" + str);
if(str.Contains("HTTP 错误 404 - 文件或目录未找到"))
{
timeIE.Enabled = false;
timeIE.Stop();
System.Threading.Thread.Sleep(3000);
CloseIE();
WriteLog("HTTP 错误 404");
//CloseWindow(activeHwnd);
//errorInforToUrl();

}

}
catch(Exception e) //白屏异常
{
//Console.WriteLine("e=============" + e.ToString());
WriteLog("白屏异常=" + e.ToString());
timeIE.Enabled = false;
timeIE.Stop();
System.Threading.Thread.Sleep(5000);
CloseIE();
//CloseWindow(activeHwnd);
//sendErrorInfor("termid=" + termid + "&errmsg=" + e.ToString());
//errorInforToUrl();
}
}
}
}
}
catch(Exception e)
{
WriteLog("SHDocVw异常=" + e.ToString());
}
}


/// <summary>
/// 关闭IE进程
/// </summary>
private void CloseIE()
{
try
{
System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcesses();

foreach (System.Diagnostics.Process myProcess in myProcesses)
{
if (myProcess.ProcessName.ToUpper() == "IEXPLORE")
{
myProcess.Kill();
}
}
}
catch(Exception e)
{
WriteLog("关闭IE异常=" + e.ToString());
}

}

运行到这里(SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();)报异常:
SHDocVw异常=System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {9BA05972-F6A8-11CF-A442-00A0C90A8F39} failed due to the following error: 80040154.
at IEBrowser.IEBrowserForm.ListenIE()
...全文
1028 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
xingyuebuyu 2010-03-01
  • 打赏
  • 举报
回复
确认shdocvw.dll有注册
shdxiang 2010-03-01
  • 打赏
  • 举报
回复
装了 还是不行 哎~~~~~~~~苦
wiki14 2010-03-01
  • 打赏
  • 举报
回复
1) Change the configuration from Any CPU to x86

2) Make a new component object with the assembly in Administrative tools - > Component services -> Computers-> My computer ->COM+Applications ->New
xingyuebuyu 2010-03-01
  • 打赏
  • 举报
回复
出错电脑和你的电脑操作系统是一样的吗?两边的配置有什么不一样的,变得和最开始的错误信息不一样了,你有做过什么修改不?
shdxiang 2010-03-01
  • 打赏
  • 举报
回复
上面说的是64位操作系统哦 我们都是32位啊
shdxiang 2010-03-01
  • 打赏
  • 举报
回复
哦 好的
我装个看看
shdxiang 2010-03-01
  • 打赏
  • 举报
回复
全部异常信息:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.OutOfMemoryException: Retrieving the COM class factory for component with CLSID {9BA05972-F6A8-11CF-A442-00A0C90A8F39} failed due to the following error: 8007000e.
at IEBrowser.IEBrowserForm.ListenIE()
at IEBrowser.IEBrowserForm.timeIE_Tick(Object sender, EventArgs e)
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINNT/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
CMSTerminal
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///d:/cmsterminal/index/cmsterminal.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINNT/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINNT/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINNT/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Interop.SHDocVw
Assembly Version: 1.1.0.0
Win32 Version: 1.1.0.0
CodeBase: file:///d:/cmsterminal/index/Interop.SHDocVw.DLL
----------------------------------------
Microsoft.mshtml
Assembly Version: 7.0.3300.0
Win32 Version: 7.0.3300.0
CodeBase: file:///d:/cmsterminal/index/Microsoft.mshtml.DLL
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
shdxiang 2010-02-27
  • 打赏
  • 举报
回复
重装了.net FrameWork 还是不行啊
问题还是出在“SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();”这里
shdxiang 2010-02-27
  • 打赏
  • 举报
回复
我在自己机子上运行也没有问题
换到别的机子就有问题了 啊啊啊啊啊啊啊啊啊
郁闷啊
xingyuebuyu 2010-02-27
  • 打赏
  • 举报
回复
我的电脑上执行没有问题.
http://wenwen.soso.com/z/q163017347.htm

按照网页上的说法,是你的电脑环境出现了问题,要重新安装 .NET Framework

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧