【问题标题】:VBA - terminating Internet Explorer processes via ShellVBA - 通过 Shell 终止 Internet Explorer 进程
【发布时间】:2016-10-02 15:04:38
【问题描述】:

包含终止 IE 实例的行会导致 Do Until 上的自动化错误或我的宏冻结。该行用于确保内存中没有旧进程。

进入debug时没有出现问题,运行Shell行稍等一下,可能IE可以在执行下一行之前加载。

我想知道是否有任何方法可以检测 IE 应用程序是否准备就绪。用name='iexplore.exe *32' 替换name='iexplore.exe' 不会使32 位进程消失,也许一个会消失并杀死其他实例可以使用循环?

Shell ("C:\Windows\system32\cmd.exe /c wmic process where name='iexplore.exe' call terminate")

Link = "http://www.example.com"
Set ie = CreateObject("InternetExplorer.Application")

ie.Navigate Link

Do Until ie.ReadyState = 4 And ie.Busy = False
    DoEvents
Loop

【问题讨论】:

    标签: vba internet-explorer


    【解决方案1】:

    WMIC 只是调用对象。你可以直接打电话给他们。

    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    
    Set colItems = objWMIService.ExecQuery("Select * From Win32_Process")
    
    For Each objItem in colItems
        'msgbox objItem.name & " " & objItem.ProcessID & " " & objItem.CommandLine
        If objItem.name = "iexplore.exe" then objItem.terminate
    Next
    

    不管是哪个位,它的名字都是IExplore.exe。

    访问 shell 文件夹(Explorer 和 Internet Explorer 窗口 [历史原因])。这将每 5 秒刷新一次所有 shell 窗口。我已经在里面添加了一个 msgbox。

        Set objShell = CreateObject("Shell.Application")
        Do 
            Set AllWindows = objShell.Windows
            Count = 0
            For Each window in AllWindows
                msgbox window.locationname
                window.refresh2 3
    `To close a shell window
    `window.close
                Count = Count + 1
            Next
            If Count = 0 then Exit Do
            Wscript.sleep 5000
        Loop
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-20
      • 1970-01-01
      • 1970-01-01
      • 2020-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多