【问题标题】:Internet Explorer exited event VB.netInternet Explorer 退出事件 VB.net
【发布时间】:2014-09-11 07:48:10
【问题描述】:

我在我的服务中使用 Process_Exited 事件,它会获取除 Internet Explorer 退出事件之外的所有事件,它会在所有资源管理器窗口关闭时获取事件,但是当我一一关闭资源管理器时,我的函数仅在最终事件时获取事件explorer 被关闭,因此该函数只能获取一个进程 ID,而不是所有 iexplorer 进程 ID

这是我的方法

 Private Sub Process_Exited(ByVal sender As Object, ByVal e As System.EventArgs)


    Dim lObj_CurrPro As Process
    Try
      '
      ' Make sure that the sender object is of process type to avoid unforseen errors
      '
      If TypeOf sender Is Process Then
        lObj_CurrPro = sender

        Call StopTracking(lObj_CurrPro.Id)
      End If

    Catch

    End Try
  End Sub

注意:我使用的是 Iexplorer8,但其进程存在问题。即使关闭 iexplorer 窗口,进程也不会退出

【问题讨论】:

  • 好吧,从技术上讲,当您打开/关闭窗口并至少打开 1 个窗口时,IE 进程仍在运行。我猜你真的想更多地寻找窗口何时关闭事件,而不是进程退出事件。
  • 我想要的是在用户关闭 IE 窗口时得到一个退出事件。
  • 你试过 windows.close() 事件吗? msdn.microsoft.com/en-us/library/…
  • 我想在 IE 窗口关闭时获取事件 window.close() 用于手动关闭窗口

标签: vb.net internet-explorer process


【解决方案1】:

这就是我所做的。此代码在每次启动 IE 时获取事件,并在每次 IE 关闭时获取事件

Imports SHDocVw
Imports System.Windows
Imports System.IO
Imports System.Management
Imports System.Object
Imports System.EventArgs
Imports System.Management.ManagementEventArgs
Imports System.Management.EventArrivedEventArgs
Imports System.Threading



Public Class Form1
  Public cd As New List(Of collectData)()
  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

  End Sub

  Dim URL As String
  Public ie As New List(Of SHDocVw.InternetExplorer)()
  Public ie_temp As New List(Of String)()
  Public count As New Integer

  Private Sub Command1_Click()

    Dim shellWins As SHDocVw.ShellWindows
    Dim explorer As SHDocVw.InternetExplorer
    Dim lObj_ShellWindows As ShellWindows
    lObj_ShellWindows = New SHDocVw.ShellWindows
    Dim lObj_ie As InternetExplorer
    Dim li_Itr As New Integer
    Dim set_CD As collectData
    Dim FILE_NAME As String = "D:\test2.txt"
    ' Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True)
    shellWins = New SHDocVw.ShellWindows

    'If ie IsNot Nothing Then
    Try

      ie.Insert(count, shellWins.Item(shellWins.Count - 1))
      set_CD = New collectData(DateTime.Now, #12:00:00 AM#, ie(count).LocationName, ie(count).LocationURL,
                    count, False)
      cd.Insert(count, set_CD)


      ' objWriter.WriteLine(ie(count).LocationName + "  Opened  " + DateTime.Now)
      ' objWriter.Close()
      count = count + 1


      lObj_ie = lObj_ShellWindows(lObj_ShellWindows.Count - 1)

      If lObj_ie.Name = "Windows Internet Explorer" Then
        AddHandler lObj_ie.OnQuit, AddressOf HandleIEQuit
      End If

    Catch ex As Exception

    End Try
    'Else

    'End If

    shellWins = Nothing
    explorer = Nothing
  End Sub
  Public Sub get_ie()
    Dim lObj_ShellWindows As ShellWindows
    lObj_ShellWindows = New SHDocVw.ShellWindows
    Dim lObj_exp As InternetExplorer
    Dim li_count As Integer
    ' Dim set_CD As collectData
    ie = Nothing
    ie = New List(Of InternetExplorer)
    li_count = 0
    For Each lObj_exp In lObj_ShellWindows
      Try
        If lObj_exp.Name = "Windows Internet Explorer" And lObj_exp.LocationURL.Contains("/") Then
          ie.Insert(li_count, lObj_exp)
          li_count = li_count + 1
        Else
        End If

      Catch ex As Exception

      End Try
    Next
    Dim tempName As String
    Dim IE_exists As New Boolean
    IE_exists = False
    If ie.Count = 0 Then
      For del As Integer = 0 To count
        cd(del).exit_time = DateTime.Now
        cd(del).exited = True
      Next
    Else
      For i As Integer = 0 To li_count - 1
        tempName = ie(i).LocationURL
        For j As Integer = 0 To count - 1
          If cd(j).url = tempName Then
            IE_exists = True
          ElseIf j = count - 1 And cd(j).url IsNot tempName Then
            cd(j).exit_time = DateTime.Now
            cd(j).exited = True
          End If

        Next
        IE_exists = False
      Next
    End If


    count = li_count
  End Sub
  Public Sub HandleIEQuit()
    Dim lObj_ShellWindows As ShellWindows

    lObj_ShellWindows = New SHDocVw.ShellWindows
    Dim do_thread As New Threading.Thread(
                                     AddressOf get_ie)
    do_thread.Start()


  End Sub
  Private Sub ManagementWatcher_StartEventArrived(ByVal PObj_Sender As Object, ByVal PObj_EventArgs As EventArrivedEventArgs)

    Dim ls_ProcessName As String

    Dim li_ProcessID As Integer


    Try

      ls_ProcessName = Path.GetFileNameWithoutExtension(PObj_EventArgs.NewEvent("ProcessName").ToString().ToUpper())
      li_ProcessID = Integer.Parse(PObj_EventArgs.NewEvent("ProcessID").ToString())


      If ls_ProcessName = "IEXPLORE" Then

        Command1_Click()
      End If


    Catch lObj_Ex As Exception

    End Try

  End Sub

  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


    Dim mObj_ManagementStartWatcher As ManagementEventWatcher = New ManagementEventWatcher("Select * From Win32_ProcessStartTrace")
    Call mObj_ManagementStartWatcher.Start()
    AddHandler mObj_ManagementStartWatcher.EventArrived, AddressOf ManagementWatcher_StartEventArrived


  End Sub
End Class

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-01
    • 2013-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多