我用以下代码关闭全部当前浏览页,但当浏览页个数大于3个的时候,他总是不能全部关闭浏览页,请问该怎么改进啊,我要他一次性全部关闭浏览页,谢谢'引用 Microsoft Internet ControlsPrivate Sub Command1_Click()
Dim ieWIN As ShellWindows
Dim ie As InternetExplorer
Set ieWIN = New ShellWindows
For Each ie In ieWIN
ie.Quit
Next
End Sub
Dim ieWIN As ShellWindows
Dim ie As InternetExplorer
Set ieWIN = New ShellWindows
For Each ie In ieWIN
ie.Quit
Next
End Sub
解决方案 »
- VB 获取外部程序内容
- 高分求,《Microsoft Visual Basic 6.0 分布式应用程序开发》电子书
- 通过如下代码已实现模糊查询,但为何只能查一次,再查就没结果,请高手看看!谢谢!
- 定义问题
- 如何为动态生成的控件添加事件?
- VarPtr的作用是什么?在语言参考中没有找到!
- run time error 53
- 怎樣使用VB程序對其調用者返回一個值?
- 如何删除正在使用中的文件
- !!!到底是vb做不到还是csdn高手不多?!包括我在内几个人对记录加锁的问题都没有一个圆满的答案??
- 我要统计我的共享软件,的一些信息! 如何连接Internet的 数据库!加如把Access数据库放在ftp上是否能访问!
- 我有一个在98下用VB5.0编的程序,但在XP下运行不了,求教解决方法?
用枚举进程的方法,找到IE进程,然后结束掉:Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function ExitProcess Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Const LOCALE_STIMEFORMAT = &H1003
Private Const LOCALE_SSHORTDATE = &H1F
Private Const WM_SETTINGCHANGE = &H1A
Private Const HWND_BROADCAST = &HFFFF&Private Declare Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Boolean
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long'获得进程的句柄
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, _
ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long
'终止进程
Private Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, _
ByVal uExitCode As Long) As Long
'创建一个系统快照
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" _
(ByVal lFlags As Long, lProcessID As Long) As Long
'获得系统快照中的第一个进程的信息
Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" _
(ByVal mSnapShot As Long, uProcess As PROCESSENTRY32) As Long
'获得系统快照中的下一个进程的信息
Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" _
(ByVal mSnapShot As Long, uProcess As PROCESSENTRY32) As LongPrivate Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szexeFile As String * 260&
End Type
Private Const TH32CS_SNAPPROCESS As Long = 2&
Dim mresult
Private Sub Command1_Click()
Dim uProcess As PROCESSENTRY32
Dim mSnapShot As Long
Dim mName As String
Dim mProcID As Long
Dim i As Integer DoEvents
uProcess.dwSize = Len(uProcess)
mSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If mSnapShot Then
mresult = ProcessFirst(mSnapShot, uProcess)
'失败则返回false
Do While mresult
i = InStr(1, uProcess.szexeFile, Chr(0))
mName = LCase$(Left$(uProcess.szexeFile, i - 1)) If UCase(mName) = UCase("iexplore.exe") Then
mProcID = OpenProcess(1&, -1&, uProcess.th32ProcessID)
'强行终止IE进程
TerminateProcess mProcID, 0&
End If
mresult = ProcessNext(mSnapShot, uProcess)
Loop
End IfEnd Sub
Option ExplicitPublic Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const WM_CLOSE = &H10
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim classname As String
Dim str5 As String
Dim len5 As Long, i As Long
str5 = String(255, 0)
len5 = 256
GetClassName hwnd, str5, 256
classname = Left(str5, InStr(1, str5, Chr(0)) - 1)
Debug.Print classname
If classname = "IEFrame" Then
PostMessage hwnd, WM_CLOSE, 0&, 0&
End If
EnumWindowsProc = True
End Function窗体,放一个按钮:
Option ExplicitPrivate Sub Command1_Click()
EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End Sub
Option Explicit
Dim dWinFolder As New ShellWindows 'IE窗口
Dim objDoc As Object
Dim objIE As ObjectPrivate Sub Command1_Click()
For Each objIE In dWinFolder
If InStr(1, objIE.FullName, "IEXPLORE.EXE", vbTextCompare) <> 0 Then
objIE.Quit
End If
Next
End Sub
楼主给分吧!!
想代码短是希望维护起来方便点哦,同时也谢谢 faysky2,等问题结帖会一起加分的,谢谢。
Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)Private Sub Command1_Click()
Dim ieWIN As ShellWindows
Dim ie As InternetExplorer
dim flag as bool
do
flag = false
Set ieWIN = New ShellWindows
For Each ie In ieWIN
ie.Quit
flag = true
Next
call sleep(1000)
loop while flag
End Sub