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 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 Long
Private 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 i As Integer
Dim flag As Boolean
flag = False
DoEvents
uProcess.dwSize = Len(uProcess)
mSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If mSnapShot Then
mresult = ProcessFirst(mSnapShot, uProcess)
Do While mresult
i = InStr(1, uProcess.szexeFile, Chr(0))
mName = LCase$(Left$(uProcess.szexeFile, i - 1))
If mName = "iexplore.exe" Then '通过进程名判断某个进程是否存在运行
flag = True
MsgBox "ie进程在运行!"
Exit Do
End If
mresult = ProcessNext(mSnapShot, uProcess)
Loop
End If
If flag = False Then
MsgBox "ie进程没有运行!"
End If
End Sub