111,097
社区成员




//捕获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());
}
}
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.